Pat
Pat

Reputation: 16901

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

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?

Upvotes: 2

Views: 5730

Answers (3)

Pat
Pat

Reputation: 16901

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

Upvotes: 2

Christopher Painter
Christopher Painter

Reputation: 55601

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

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

Upvotes: 1

Wim Coenen
Wim Coenen

Reputation: 66753

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

Upvotes: 3

Related Questions