安装 MSI 时如何以编程方式检测成功或失败? [英] How do I programmatically detect success or failure when installing an MSI?

查看:29
本文介绍了安装 MSI 时如何以编程方式检测成功或失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个引导程序应用程序,它安装了几个 MSI 包.但是,如果安装失败,Windows 安装程序似乎不会返回任何错误代码.例如,如果我点击取消",以下命令行测试不会打印失败":

I have a bootstrapper application which installs several MSI packages. However, it seems that windows installer does not return any error code if the installation fails. For example, the following command line test does not print "failed" if I hit "cancel":

msiexec /i myinstaller.msi || echo failed

鉴于缺乏错误反馈,检测安装失败的最佳方法是什么?

Given the lack of error feedback, what is the best way to detect an installation failure?


正如接受的答案所暗示的那样,实际上返回了错误代码.出于某种原因,我的测试用例只能在从批处理文件中执行时按预期工作,而不是直接在命令行中输入.


As the accepted answer suggests, an error code is actually returned. For some reason my test case only works as expected when executed from a batch file, rather than typed directly at a command line.

推荐答案

其实msiexec 确实会返回错误码,两个成功码分别是0(成功)和3010(成功,需要重新启动).也许 cmd.exe 在你的例子中做了一些不需要的魔法(比如在 msiexec 完成之前返回),但是我在通过 VBScript 的 WScript.Shell Run(bWaitOnReturn = True).

Actually, msiexec does return error codes, the two success codes being 0 (success) and 3010 (success, reboot required). Maybe cmd.exe does some unwanted magic in your example (like returning before msiexec has finished), but I successfully read msiexec error codes when executing it via VBScript's WScript.Shell Run (with bWaitOnReturn = True).

尝试将以下内容放入 test.vbs 文件中,然后使用 cscript test.vbs 执行它:

Try throwing the following in a test.vbs file and then executing it with cscript test.vbs:

Set WshShell = WScript.CreateObject("WScript.Shell")
MsgBox(WshShell.Run("msiexec /i myinstaller.msi", , true))

如果您点击取消,它应该弹出一个非零值.

It should pop up with a non-zero value if you hit Cancel.

这篇关于安装 MSI 时如何以编程方式检测成功或失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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