简体   繁体   English

从Setup.exe引导程序调用时如何确定MSI的返回码

[英]How to determine return code of MSI when it's called from Setup.exe bootstrapper

We have a Win Forms application that is built from VS 2010, and has a VS Setup project which creates an MSI and a Setup.exe as the bootstrapper. 我们有一个从VS 2010构建的Win Forms应用程序,还有一个VS Setup项目,该项目创建MSI和Setup.exe作为引导程序。

The MSI is included in a self-extracting 7zip file that calls a batch file when it extracts, and that batch file in the past would execute the MSI directly with the /passive switch, and it would give different messages depending on the return code, like shown below... MSI包含在一个自解压的7zip文件中,该文件在提取时会调用一个批处理文件,过去该批处理文件会直接通过/passive开关执行MSI,并且会根据返回代码给出不同的消息,如下图所示

IF %ErrorLevel% EQU 1602 GOTO :INSTALL_CANCELLED
IF %ErrorLevel% NEQ 0 GOTO :INSTALL_FAILED

Executing the MSI directly means that the bootstrap process is skipped and prerequisites don't get installed if they are needed. 直接执行MSI意味着将跳过引导过程,并且在需要时不安装先决条件。 So I want to change this so that we include the Setup.exe bootstrapper in the package, and execute Setup.exe /passive instead of calling the MSI directly. 因此,我想更改此设置,以便我们在程序包中包含Setup.exe引导程序,并执行Setup.exe /passive而不是直接调用MSI。

This works fine, unless something goes wrong, in which case the %ErrorLevel% is still returned as 0. I'm assuming this is because Setup.exe calls the MSI, and regardless of whether the MSI hit an error or not, the Setup.exe exits with return code of 0. 除非出现问题,否则此方法工作正常,在这种情况下, %ErrorLevel%仍返回0。我假设这是因为Setup.exe调用了MSI,并且无论MSI是否遇到错误,安装程序.exe退出,返回码为0。

Is there any way to detect whether the MSI returns a non-zero code if I'm calling Setup.exe instead of calling the MSI directly? 如果我调用Setup.exe而不是直接调用MSI,是否可以检测到MSI是否返回非零代码?

*EDIT *编辑

I found this MSDN article, which says the following... 我找到了这篇MSDN文章,内容如下:

Note that the Setup.exe Bootstrapper sample does not need to check for error codes generated by the host application, myapp, because this is not a silent install and all errors are displayed to the user through the Windows Installer user interface. 请注意,Setup.exe Bootstrapper示例不需要检查主机应用程序myapp生成的错误代码,因为这不是静默安装,并且所有错误都通过Windows Installer用户界面显示给用户。

https://msdn.microsoft.com/en-us/library/xhz1cfs8(v=vs.90).aspx#cpconsetupexebootstrappersampleoperationsanchor4 https://msdn.microsoft.com/en-us/library/xhz1cfs8(v=vs.90).aspx#cpconsetupexebootstrappersampleoperationsanchor4

WTF do they mean "Because this is not a silent install"? WTF是指“因为这不是静默安装”吗? The hell it isn't. 该死的不是。 They support passing the /passive switch to make it a silent install, but then they give you no way to get a return code from the MSI, in their words "because this is not a silent install". 他们支持传递/ passive开关以使其成为静默安装,但是随后他们就没有办法让您从MSI获取返回代码,因为它们的意思是“因为这不是静默安装”。

Well now I'm just ranting about a deprecated Visual Studio feature, so I guess it is what it is. 好吧,现在我只是在夸耀已过时的Visual Studio功能,所以我想这就是事实。

The setup.exe would have to surface the exit code. setup.exe将不得不显示退出代码。

FWIW, Windows Installer XML (WiX) has a bootstrapper (Burn) that you can customize (implementing a bootstrapper application layer) and do anything you want to do. FWIW,Windows Installer XML(WiX)具有一个引导程序(Burn),您可以对其进行自定义(实现引导程序应用程序层)并执行任何您想做的事情。

Edit: I misread the question; 编辑:我读错了问题; I thought you were running someone else's setup project. 我以为您在运行别人的安装项目。 However, since this answer might still be useful to someone, and I've already written it, I'm posting it anyway. 但是,由于此答案可能仍然对某人有用,而且我已经写了它,所以无论如何我都会发布它。

Not easily, and not from batch. 不容易,也不是批处理。

If you launch the setup process within a job object you can assign it to a completion port and listen for the JOB_OBJECT_MSG_NEW_PROCESS message. 如果您在作业对象中启动设置过程,则可以将其分配给完成端口,并监听JOB_OBJECT_MSG_NEW_PROCESS消息。 You would then have to open the new process, check whether it is msiexec.exe and keep the process handle if so. 然后,您将不得不打开新进程,检查它是否是msiexec.exe并保持进程句柄(如果是)。

When the setup process is finished, use the stored process handle for msiexec.exe to retrieve the exit code via GetExitCodeProcess() . 设置过程完成后,使用msiexec.exe的存储过程句柄通过GetExitCodeProcess()检索退出代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM