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

时间:2010-11-09 16:56:44

标签: installer windows-installer nsis

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

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

3 个答案:

答案 0 :(得分:3)

您可以查看error code returned by msiexec。例如,“已安装此产品的另一个版本”返回1638。

我不是NSIS用户,但是我从NSIS文档中可以看出,我认为你可以$0ExecWait "msiexec -i $TEMP\MyMsi.msi" $0 capture the exit code这样:{/ p>

{{1}}

答案 1 :(得分:2)

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

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

答案 2 :(得分:1)

结帐List of error codes and error messages for Windows Installer processes

在这种情况下,msiexec应该返回1638的代码。