确定已经安装了MSI文件的MSIEXEC退出代码 [英] Determine msiexec exit code when msi file already installed

查看:248
本文介绍了确定已经安装了MSI文件的MSIEXEC退出代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在另一个进程中启动msiexec并等待退出:

  var p =新进程
{
StartInfo =
{
FileName = msiexec,
参数= string.Format( / i \ {0} \ / qb,@ c:\ \install\setup.msi),
动词= runas
}
};
p.Start();
p.WaitForExit();
int exitCode = p.ExitCode;

如果先前未安装setup.msi,它将安装为静默模式并返回0。它正常。



但是,如果已经安装setup.msi(第二次启动此代码),则安装不会开始,并且返回代码0-成功!但是实际上,尚未建立文件,因为已经安装了产品。我如何确定这种情况?

解决方案

您收到的退出代码为 0 ,因为已经安装了该产品,并且您没有尝试安装新版本。换句话说,您的MSI没有新的产品代码和版本号,因此MSIExec安装程序会将其视为重新配置,然后退出。我通过打开/ log 切换,并在两次安装我的一个MSI文件后读取输出。


MSI(c)(98:EC)[ 15:19:27:912]:产品:产品名称-配置
已成功完成。 MSI(c)(98:EC)[15:19:27:912]:Windows
安装程序重新配置了产品。产品名称:产品名称。
产品版本:4.8.22。产品语言:1033。制造商:制造商。重新配置成功或错误状态:0。


如果您尝试安装产品的新版本而MSI未配置为删除以前的版本,您将收到错误代码 1638 。请在此处查看错误代码列表: MSDN



如果要检查产品是否已经安装了现有的MSI信息(不是升级),则需要在以下位置检查注册表: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\卸载\YourProductCode



安装完毕(根据系统/注册表-可能文件已删除,但仍被认为已安装),您可以尝试使用 / x 卸载它,或者 /卸载开关,然后重新安装。您还可以使用 / fa 开关进行修复并重新安装所有文件。



msiexec.exe / x ProductCode 将其卸载。然后,您可以在那之后再次运行安装。
msiexec.exe / fa ProductCode 将修复所有文件。 / f开关在重新安装文件方面有很多不同的选择,因此您最好阅读我上面发布的msiexec开关文章的链接。



有关msiexec的其他注意事项:



/ qb 显示基本的用户界面。您可能需要 / qn
在设置实时更新软件时,我遇到了很多问题,我必须确保使用



<$ p $从system32调用msiexec p> p.StartInfo.FileName == Path.Combine(System.Environment.ExpandEnvironmentVariables(%windir%\\system32), MSIExec.exe);


I launch msiexec in another process and wait for exit:

var p = new Process
{
    StartInfo =
    {
        FileName = "msiexec",
        Arguments = string.Format("/i \"{0}\" /qb", @"c:\install\setup.msi"),
        Verb = "runas"
    }
};
p.Start();
p.WaitForExit();
int exitCode = p.ExitCode;

If the setup.msi has not been previously installed it is installing to silent mode and returns 0. It normal.

But if setup.msi already installed (launch this code second time), installation not starting and return code 0 - success result! But in fact, the files have not been established, because product is already installed. How I can determine this situation?

解决方案

You received an exit code of 0 because the product is already installed and you are not attempting to install a new version. In otherwords, your MSI does not have a new Product Code and version number, therefore the MSIExec installer considers it a reconfiguration, and exits. I tested this out by turning on the /log switch and reading the output after installing one of my MSI files twice.

MSI (c) (98:EC) [15:19:27:912]: Product: Product Name -- Configuration completed successfully. MSI (c) (98:EC) [15:19:27:912]: Windows Installer reconfigured the product. Product Name: Product Name. Product Version: 4.8.22. Product Language: 1033. Manufacturer: Manufacturer. Reconfiguration success or error status: 0.

If you were trying to install a new version of your product and your MSI was not configured to remove previous versions, you would receive an error code of 1638. See list of error codes here: MSDN

If you want to check if the product is already installed with the existing MSI information (not an upgrade) you would need to check the registry at: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\YourProductCode

If it turns out it is installed (according to the system/registry -- maybe the files were deleted but it still is considered to be installed) you can try uninstalling it using the /x or /uninstall switch and then reinstalling. You could also use the /fa switch to do a repair and reinstall all files.

msiexec.exe /x ProductCode will uninstall it. Then you can run the install again after that. msiexec.exe /fa ProductCode will do a repair of all files. The /f switch has a lot of different options for how it reinstalls files, so you'd do well to read the link to the msiexec switches article I posted above.

Some other notes about msiexec:

/qb displays a basic user interface. You probably want /qn. When I was setting up my live-update software I ran into a bunch of problems, I had to make sure I called msiexec from system32 by using

p.StartInfo.FileName == Path.Combine(System.Environment.ExpandEnvironmentVariables("%windir%\\system32"), "MSIExec.exe"); 

这篇关于确定已经安装了MSI文件的MSIEXEC退出代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆