Archive: Silent uninstall always exits with errorlevel


Silent uninstall always exits with errorlevel
Hi,

I have the following problem.
Calling the uninstaller in silent mode from a batch file which checks the returned error level, always gives error level 2.

Adding SetErrorLevel 0 as last instruction in the uninstaller section DOES NOT help.

Second strange behaviour:
I placed 2 Messageboxes with debug output into the uninstaller section. Both MessageBoxes appear one after the other, but when the first one appears, the installer has already finished and returned to the calling batch file.

1. What happens after this section, that sets the errorlevel to 2

2. Why do the Messageboxes NOT interrupt the program and wait until OK is pressed?



Section Uninstall
SetDetailsPrint None

StrCmp $MustUpdate "1" SkipUninstDriver
Call un.InstallDriver

SkipUninstDriver:
; Can't uninstall if uninstall log is missing!
IfFileExists "$INSTDIR\${UninstLogfileName}" NormalUninst
# MessageBox MB_YESNO|MB_ICONSTOP "$(UninstLogMissing)$\r$\n$(ForcedUninst)" /SD IDNO IDYES ForcedUninst
# Abort

ForcedUninst:
StrCmp "$INSTDIR" "${DEFAULTDIR}" 0 NoUninstall
Delete "$INSTDIR\*.*"
Delete "${SYSDRIVERDIR}\$DriverBaseName${SYS_EXT}"

RmDir /r "$INSTDIR"
RmDir /r "$SMPROGRAMS\${OEM}\${PRODUCT}"
Push "RegOnly"
goto DoUninst

NoUninstall:
StrCpy $UserError "Unable to uninstall: $INSTDIR\${UninstLogfileName} missing and not installed in ${DEFAULTDIR}"
MessageBox MB_ICONEXCLAMATION|MB_OK "$UserError"
goto UnInstDone

NormalUninst:
SetDetailsPrint None
Push $R0
Push $R1
Push $R2
Push $R4

Push ""
DoUninst:
Call un.NormalUninst

UninstDone:
${Log} "[ResponseResult]"
StrCpy $R0 "0"
MessageBox MB_ICONINFORMATION|MB_OK "UserError=$UserError ($R0)"
StrCmp $UserError "" LogResult
StrCpy $R0 "2"

LogResult:
${Log} "ResultCode=$R0"
SetErrorLevel $R0
StrCmp $UserError "" +2
${Log} "ErrMessage=$UserError"

FileClose $InstLog
SetFileAttributes "$InstLogDir\$InstallLog" READONLY

Pop $R4
Pop $R2
Pop $R1
Pop $R0

StrCmp $UserError "" Done
Call un.closelog
Abort
Done:
MessageBox MB_ICONINFORMATION|MB_OK "Setting ErrorLevel to 0"

SetErrorLevel 0
SectionEnd


From the helpfile: errorlevel: 2 = Installation aborted by script. And you do have an Abort in there


Originally posted by Anders
From the helpfile: errorlevel: 2 = Installation aborted by script. And you do have an Abort in there
Yes, but if you look at the code, you can see, that the Abort is only executed if UserError != "", but UserError is empty (MessageBoxOutput is UserError= (0))
and the Logfile contains ResultCode=0 but NO line with ErrMessage=, so $UserError MUST BE empty.

Added a Messagebox saying "Aborting uninstall" immediately before Abort and it DID NOT show up!!

Closed:Silent uninstall always exits with errorlevel

Originally posted by Anders
From the helpfile: errorlevel: 2 = Installation aborted by script. And you do have an Abort in there
Yepp! It was Abort, but not that one in the uninstall section, but the one I put in .oninit where I check the commandline to allow calling the installer with /REMOVE, invoking the UNINST of an already installed version.
After the DoRemove I HAVE to abort the installer, since I don't want to continue the installer when called with /REMOVE . :-((

So I have to look for a way to quit the installer in .oninit with the errorlevel returned by uninst.exe...

SetErrorLevel+Quit ?


Originally posted by Anders
SetErrorLevel+Quit ?
Yes, did it that way and it now it works as expected.

Did you ever find the answer for:
Why do the Messageboxes NOT interrupt the program and wait until OK is pressed?

also how are you checking the returned exit code from the uninstaller? Execwait?

I'm using the UAC plugin to elevate user access and the uninstaller creates Au_.exe which is a copy of the unintaller in a temp dir, and runs that. Thus, I believe my uninstaller will always exit with error code 0, even though Au_.exe won't or may still be running. It this makes sense to anybody, do you have any ideas on how to get the exit code of Au_.exe which is not created until the uninstaller is executed?


http://nsis.sourceforge.net/When_I_u...he_uninstaller