Archive: Exit code on embedded installers


Exit code on embedded installers
Bad topic title I know.

I'm running an installer from my NSIS installer/script via the following:

Section "app2" Section2

; Set Section properties
SetOverwrite on
SectionIn RO

;Set Section Files and Shortcuts
SetOutPath "$INSTDIR\Install\"
File "..\..\source\biginstaller\app2.exe"
ExecWait "$INSTDIR\Install\app2.exe"

SectionEnd


However I want to abort the whole script/installer if this installer fails to complete. I.e. if the exit code != 0.
I did find a 'Useful Script' that mentions this, but I'm being intellectually challenged and cant find how to apply it, as the example seems to omit this section.

http://nsis.sourceforge.net/Embedding_other_installers#Using_the_return_value_from_the_ExecWait
.

Suggestions please?

There is an optional parameter to capture the exit code. The manual is your friend.


I saw that, however getting the exit code and handling it are different things. Its the handling that I'm struggling with.


First of all you need to figure out what ExitCode the installer you run will return in for what situation.

This depends on the individual installer and may not be answered in general.

Then simply use a "StrCmp $1 <VAL> <GoIfEqual> <Otherwise>" to decide where to jump, depending on the ExitCode.

ExecWait '"$INSTDIR\Install\app2.exe"' $1
StrCmp $1 0 Success ; Jump to 'Success' if (and only if) ExitCode was '0'

MessageBox MB_OK "Failed to install. Setup will exit!"
Quit

Success:
MessageBox MB_OK "Installed correctly"


For more complex things, you may want to have a look at ${switch} from LogicLib.nsh ;)

Or, preferably, use the logiclib and do:
${If} $1 == "<VAL>"
;stuff
${Else}
;other stuff
${EndIf}


Include LogicLib.nsh and then

ExecWait "$INSTDIR\Install\app2.exe" $0
${If} $0 <> 0
; app2 has failed, must cleanup and stop
...
${EndIf}
or
ExecWait "$INSTDIR\Install\app2.exe" $0
${If} $0 = 0
; app2 success, continue remaining operations
...
${EndIf}


(Edit: overlapping posts - MSG and I are suggesting the same thing.)

...wow, look at us being all helpful today. :P