Check return code (or something else) to ensure MSI has installed correctly

白昼怎懂夜的黑 提交于 2019-12-02 01:46:05

问题


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?


回答1:


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



回答2:


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):

!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



回答3:


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

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



来源:https://stackoverflow.com/questions/4136294/check-return-code-or-something-else-to-ensure-msi-has-installed-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!