Skip to content
⌘ NSIS Forum Archive

InstallOptions and aborting the uninstaller

7 posts

coco_vc#

InstallOptions and aborting the uninstaller

Hi all,

I need to do the following: when uninstalling, a custom page should be shown with 2 radio buttons:
a)- if one is selected I have to check that the user is admin and in case it is go further, if not abort the uninstaller with an error
b)- if the other radio-button is selected I have to run an .exe from the installation directory and abort right away the uninstaller (doesn't need to wait until the exe is finished)

What I did:
=============
- defined the page:
UninstPage custom un.UninstallModePage un.ValidateSelection ;Custom page
- reserve:
ReserveFile "UninstallMode.ini"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
- Extract InstallOptions INI files
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "UninstallMode.ini"
- show it:
Function un.UninstallModePage ;UninstallModePage defined with Page command
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "UninstallMode.ini"
FunctionEnd
- I added the un.ValidateSelection in order to do here the needed things for a) and b)
Function un.ValidateSelection ; when the user finished with the selection
; check if the selection is the second radio button and if yes for now do a MsgBox and abort the whole uninstaller
!insertmacro MUI_INSTALLOPTIONS_READ $INI_VALUE "UninstallMode.ini" "Field 2" "State"
StrCmp $INI_VALUE "1" 0 +3
MessageBox MB_OK "Here we should run another exe and then abort"
Abort ; abort somehow the whole uninstaller !!!

; check if the selection is the first radio button and if yes check that the current user is admin otherwise abort the whole uninstaller
!insertmacro MUI_INSTALLOPTIONS_READ $INI_VALUE "UninstallMode.ini" "Field 1" "State"
StrCmp $INI_VALUE "1" 0 done
ClearErrors
UserInfo::GetAccountType
Pop $1
StrCmp $1 "Admin" 0 +3
MessageBox MB_OK 'User is in the Administrators group'
Goto done
MessageBox MB_OK 'User is NOT in the Administrators group, so we should ABORT here somehow'
Abort ; abort somehow the whole uninstaller !!!
done:
FunctionEnd

Problems:
===========
- In both cases a) and b) I need to at some point completely abort the uninstaller. Those points are showed in un.ValidateSelection, check for "abort somehow the whole uninstaller !!!". How can I abort the whole uninstaller in those cases? For b) with no error message, and for a) with a MsgBox saying that the current user needs to be admin?
- In case of b) where and how should I run the exe just before aborting the whole uninstaller?

Sorry for the long post and thx in advance,
Viv
dienjd#
I think you want to use Quit instead of Abort. Example:

!insertmacro MUI_INSTALLOPTIONS_READ $INI_VALUE "UninstallMode.ini" "Field 2" "State"
StrCmp $INI_VALUE "1" 0 +3
Exec app.exe
Quit
For the case where you want to message the user that they are not an admin, use Quit immediately after your MessageBox.
dandaman32#
Using Quit would kill the installer, without cleaning up anything in $PLUGINSDIR. The best choice here would be Return.

-dandaman32
kichik#
dandaman32, that's not true. The $PLUGINSDIR clean-up has nothing to do with Quit. It's always done. There may a problem deleting InstallOptions.dll, if it's still in use, but it will be removed after reboot.

coco_vc, please use [ code ] or attach your scripts.
dandaman32#
dandaman32, that's not true. The $PLUGINSDIR clean-up has nothing to do with Quit. It's always done. There may a problem deleting InstallOptions.dll, if it's still in use, but it will be removed after reboot.
Interesting. According to the docs, Quit closes the installer almost immediately. In the ExperienceUI I call .onGUIend (which cleans stuff up from $PLUGINSDIR) and then use Quit.

Anyway Return would have just jumped to the next page, now that I think about it. If you're using the ExperienceUI you could use
StrCpy $XPUI_ABORTED 1
Return
to trigger the Abort page if that's enabled.

-dandaman32
coco_vc#
kichik, I will [ code ] next time. Sorry, wasn't aware of this.

The Quit did the trick. Thx.
So it's ok that I did all of these in the un.ValidateSelection?

Thx,
Viv