检查返回代码(或其他代码)以确保 MSI 已正确安装

发布于 2024-10-01 13:28:17 字数 238 浏览 5 评论 0原文

我正在使用 NSIS 安装一些 MSI。我正在使用 ExecWait“msiexec /passive /liare+ ${SETUP_LOG_FILE} -i $TEMP\MyMsi.msi”。当 MSI 与已安装的应用程序版本相同时,安装会失败(“已安装此产品的另一个版本”),但 NSIS 会继续运行,就好像没有任何问题一样。 (但日志文件揭示了问题。)

如何检查 MSI 安装是否失败?如果确实失败,停止 NSIS 安装的正确方法是什么?

I am using NSIS to install some MSIs. I'm using ExecWait "msiexec /passive /liare+ ${SETUP_LOG_FILE} -i $TEMP\MyMsi.msi". When the MSI is of the same version as an installed app, it fails the installation (“Another version of this product is already installed”), but NSIS continues on as if nothing is wrong. (But the log file reveals the problem.)

How can I check to see if the MSI install failed? If it did fail, what is the correct way to halt the NSIS installation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挽梦忆笙歌 2024-10-08 13:28:17

您可以检查msiexec返回的错误代码。例如,“此产品的另一个版本已安装”返回 1638。

我不是 NSIS 用户,但从 NSIS 文档中可以看出,我认为您可以 $0 中的 msiexec 捕获退出代码,如下所示:

ExecWait "msiexec -i $TEMP\MyMsi.msi" $0

You can check the error code returned by msiexec. For example, "Another version of this product is already installed" returns 1638.

I'm not an NSIS user, but from what I can tell from the NSIS documentation I think you can capture the exit code from msiexec in $0 like this:

ExecWait "msiexec -i $TEMP\MyMsi.msi" $0
陈年往事 2024-10-08 13:28:17

离开@Wim 的答案,这是我的解决方案。 (我需要安装的应用程序的名称是“Evergreen Programmer”,并且还有代码来检查CPU是32位还是64位。)我不喜欢Abort的方式不过,使 GUI 看起来(用户必须单击“取消”):

显示使用 Abort 的结果的屏幕截图

!include "x64.nsh"

Function CheckReturnCode
  DetailPrint "MSI return code was $0"  
  ${If} $0 != 0 
    Abort "There was a problem installing the application."
  ${EndIf}
FunctionEnd

Section "FrameworkAndApp" SecFrameworkApp

  SetOutPath "$TEMP"
  File /oname=EvergreenProgrammerSetup.msi "${SETUP_FILE}"
  File /oname=EvergreenProgrammerSetup64.msi "${SETUP_FILE_64}"

InstallEvergreenProgrammer:
  Push "Starting Evergreen Programmer Install Version ${MAJOR_VERSION}.${MINOR_VERSION}.${REVISION}"
  Call DebugLog
  DetailPrint "Starting Evergreen Programmer Install Version ${MAJOR_VERSION}.${MINOR_VERSION}.${REVISION}"
  IfSilent InstallAppWithNoProgressBar
${If} ${RunningX64}
  DetailPrint "64-bit detected"
  ExecWait "msiexec /passive /liare+ ${SETUP_LOG_FILE} -i $TEMP\EvergreenProgrammerSetup64.msi" $0
${Else}
  ExecWait "msiexec /passive /liare+ ${SETUP_LOG_FILE} -i $TEMP\EvergreenProgrammerSetup.msi" $0
${EndIf}
  Call CheckReturnCode
  SetRebootFlag true
  Goto EndInstall

InstallAppWithNoProgressBar:
${If} ${RunningX64}
  DetailPrint "64-bit detected"
  ExecWait "msiexec /quiet /liare+ ${SETUP_LOG_FILE} -i $TEMP\EvergreenProgrammerSetup64.msi" $0
${Else}
  ExecWait "msiexec /quiet /liare+ ${SETUP_LOG_FILE} -i $TEMP\EvergreenProgrammerSetup.msi" $0
${EndIf}
  Call CheckReturnCode
  SetRebootFlag true
  Goto EndInstall

EndInstall:
  IfRebootFlag PromptForReboot
  Return
PromptForReboot:
  IfSilent SkipReboot
  MessageBox MB_OK "The application will not function correctly without a reboot or log off."

SkipReboot:

SectionEnd

Going off of @Wim's answer, here is my solution. (The name of the app I need to install is "Evergreen Programmer", and there is also code to check if the CPU is 32- or 64-bit.) I don't like the way Abort makes the GUI look, though (the user has to click Cancel):

screenshot showing the result of using Abort

!include "x64.nsh"

Function CheckReturnCode
  DetailPrint "MSI return code was $0"  
  ${If} $0 != 0 
    Abort "There was a problem installing the application."
  ${EndIf}
FunctionEnd

Section "FrameworkAndApp" SecFrameworkApp

  SetOutPath "$TEMP"
  File /oname=EvergreenProgrammerSetup.msi "${SETUP_FILE}"
  File /oname=EvergreenProgrammerSetup64.msi "${SETUP_FILE_64}"

InstallEvergreenProgrammer:
  Push "Starting Evergreen Programmer Install Version ${MAJOR_VERSION}.${MINOR_VERSION}.${REVISION}"
  Call DebugLog
  DetailPrint "Starting Evergreen Programmer Install Version ${MAJOR_VERSION}.${MINOR_VERSION}.${REVISION}"
  IfSilent InstallAppWithNoProgressBar
${If} ${RunningX64}
  DetailPrint "64-bit detected"
  ExecWait "msiexec /passive /liare+ ${SETUP_LOG_FILE} -i $TEMP\EvergreenProgrammerSetup64.msi" $0
${Else}
  ExecWait "msiexec /passive /liare+ ${SETUP_LOG_FILE} -i $TEMP\EvergreenProgrammerSetup.msi" $0
${EndIf}
  Call CheckReturnCode
  SetRebootFlag true
  Goto EndInstall

InstallAppWithNoProgressBar:
${If} ${RunningX64}
  DetailPrint "64-bit detected"
  ExecWait "msiexec /quiet /liare+ ${SETUP_LOG_FILE} -i $TEMP\EvergreenProgrammerSetup64.msi" $0
${Else}
  ExecWait "msiexec /quiet /liare+ ${SETUP_LOG_FILE} -i $TEMP\EvergreenProgrammerSetup.msi" $0
${EndIf}
  Call CheckReturnCode
  SetRebootFlag true
  Goto EndInstall

EndInstall:
  IfRebootFlag PromptForReboot
  Return
PromptForReboot:
  IfSilent SkipReboot
  MessageBox MB_OK "The application will not function correctly without a reboot or log off."

SkipReboot:

SectionEnd
勿挽旧人 2024-10-08 13:28:17

查看 Windows Installer 进程的错误代码和错误消息列表

msiexec 应该在以下位置返回代码 1638那种情况。

Checkout List of error codes and error messages for Windows Installer processes

msiexec should have returned a code of 1638 in that situation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文