Archive: uninstallation errors


uninstallation errors
  Hi,
in my installer, during .onInit I call UninstallPreviousSoftware, code below. I think that there are two problems with this code and would appreciate advice.
1. If my product has already been installed then I call its uninstaller using ExecWait, before continuing with the new installer. When the old uninstaller is running, if I cancel out of it, I was expecting it to return an error code that I could pick up as such. However I do not seem to get any error returned and so the following code will then delete the old uninstaller.
2. I am not totally sure that the HideWindow and BringToFront code is working, I have seen times when after the uninstaller has finished, the installer is still running in the task manager but it seems to be hidden.

Function UninstallPreviousSoftware

#if a previous version of the software is already installed, then uninstall it. When uninstalling:
#- if the new software is an updater installer, then tell the uninstaller, using a command line parameter,
# that a subsequent reinstall will take place, so that it *should not delete everything*
#- if the new software is a full installer, then tell the uninstaller that a subsequent reinstall
# will take place, so that it *should delete everything*

Push $R0
Push $R1
Push $R2

ReadRegStr $R0 "HKEY_LOCAL_MACHINE" "${MY_ADD_REMOVE_PROGRAMS_REGISTRY_KEY}" "UninstallString"

${If} "" != $R0
IfFileExists $R0 0 done
HideWindow

ClearErrors

StrCpy $R1 ""

!ifdef UPDATER_BUILD
StrCpy $R1${MY_UPDATER_UNINSTALL_COMMAND_LINE_PARAMETER}
!endif

ExecWait "$R0 $R1 _?=$INSTDIR" $R2

${If} ${Errors}
MessageBox MB_OK "uninstall error = $R2"
ClearErrors
${Else}
Delete "$R0"
RMDir "$INSTDIR"
${EndIf}

BringToFront
${EndIf}

done:

Pop $R2
Pop $R1
Pop $R0
FunctionEnd
>

1. I googled for 'nsis uninstaller return codes' and the first hit pointed me at this: http://nsis.sourceforge.net/Docs/AppendixD.html#D.1 The solution you seek is shown there. Next time please google first, ask later. (And anyway, you could just read your registry entry again to see if uninstallation was executed properly.)

2. Not sure how that works. But you can always just use the Banner plugin to let the installer 'sleep' while uninstallation is performed.


BTW, if you specify a returncode variable (in this case $R2) the errorflag will not be set when a returncode other then 0 is returned.
So you should check $R2 not equal to 0 as well.
See http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.1.4


Hi MSG, yes I had read the documentation but it seemed unclear to me about the fact that if I called ExecWait with $R2, that the error would be placed in $R2 but would not be raised as an error I could query with ${If} ${Errors}. Thanks to jpderuiter's advice, I changed the code to the snippet below and all now works :)


ExecWait "$R0 $R1 _?=$INSTDIR" $R2


>${If} ${Errors}
GetErrorLevel $R2
MessageBox MB_OK "uninstall error = $R2"
ClearErrors
Abort
>${ElseIf} 0 != $R2
DetailPrint "uninstall error = $R2"
ClearErrors
Abort
>${Else}
Delete "$R0"
RMDir "$INSTDIR"
>${EndIf}

Just FYI, you don't have to ClearErrors when you detect them. The detection (either IfErrors or ${If}${Errors}) will clear the error flag.