Skip to content

Commit

Permalink
fix(nsis): Error handling if uninstaller cannot be launched (#4674)
Browse files Browse the repository at this point in the history
This adds error handling if the old-uninstaller.exe process cannot be
launched. Previously the error flag was not checked after calling
ExecWait (ifErrors was missing).

In case old-uninstaller.exe cannot be launched from inside $PLUGINSDIR
(a.k.a a subfolder of the Temp directory) - for example due to a group policy
restriction that prevents executables from being launched that reside
inside the Temp folder - the original uninstaller residing inside the
application install directory is executed in place.

If this still fails the update is aborted.
  • Loading branch information
sa-MatteoHausner authored Feb 23, 2020
1 parent 5390bb6 commit 442493b
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/app-builder-lib/templates/nsis/include/installUtil.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Var /GLOBAL isTryToKeepShortcuts
# http://stackoverflow.com/questions/24595887/waiting-for-nsis-uninstaller-to-finish-in-nsis-installer-either-fails-or-the-uni
Function uninstallOldVersion
Var /GLOBAL uninstallerFileName
Var /Global uninstallerFileNameTemp
Var /GLOBAL installationDir
Var /GLOBAL uninstallString
Var /GLOBAL rootKey
Expand Down Expand Up @@ -142,9 +143,6 @@ Function uninstallOldVersion
Goto Done
${endif}

!insertmacro copyFile "$uninstallerFileName" "$PLUGINSDIR\old-uninstaller.exe"
StrCpy $uninstallerFileName "$PLUGINSDIR\old-uninstaller.exe"

${if} $installMode == "CurrentUser"
${orIf} $rootKey == "HKEY_CURRENT_USER"
StrCpy $0 "/currentuser"
Expand All @@ -170,7 +168,20 @@ Function uninstallOldVersion
StrCpy $0 "$0 --updated"
${endif}

ExecWait '"$uninstallerFileName" /S /KEEP_APP_DATA $0 _?=$installationDir' $R0
StrCpy $uninstallerFileNameTemp "$PLUGINSDIR\old-uninstaller.exe"
!insertmacro copyFile "$uninstallerFileName" "$uninstallerFileNameTemp"

ExecWait '"$uninstallerFileNameTemp" /S /KEEP_APP_DATA $0 _?=$installationDir' $R0
ifErrors 0 ExecErrorHandler
# the execution failed - might have been caused by some group policy restrictions
# we try to execute the uninstaller in place
ExecWait '"$uninstallerFileName" /S /KEEP_APP_DATA $0 _?=$installationDir' $R0
ifErrors 0 ExecErrorHandler
# this also failed...
DetailPrint `Aborting, uninstall was not successful. Not able to launch uninstaller!`
SetErrorLevel 5
Abort "Cannot uninstall"
ExecErrorHandler:
${if} $R0 != 0
DetailPrint `Aborting, uninstall was not successful. Uninstaller error code: $R0.`
SetErrorLevel 5
Expand Down

0 comments on commit 442493b

Please sign in to comment.