Menu

#1288 Uninstall does not work correctly with MultiUser

3.0 Series
open
nobody
None
5
2022-11-12
2022-10-29
JakobDev
No

Take a look at this example installer:

Name "Test"
OutFile "Installer.exe"
Unicode True

!include "LogicLib.nsh"
!include "x64.nsh"

!define MULTIUSER_USE_PROGRAMFILES64
!define MULTIUSER_INSTALLMODE_INSTDIR "$(^Name)"
!define MULTIUSER_INSTALLMODE_COMMANDLINE
!define MULTIUSER_EXECUTIONLEVEL Highest
!define MULTIUSER_MUI

!include "MultiUser.nsh"
!include "MUI2.nsh"

!insertmacro MUI_PAGE_WELCOME
!insertmacro MULTIUSER_PAGE_INSTALLMODE
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

!insertmacro MUI_LANGUAGE "English"

Function .onInit
    !insertmacro MULTIUSER_INIT
FunctionEnd

Function un.onInit
    !insertmacro MULTIUSER_UNINIT
FunctionEnd

Section
    SetOutPath "$INSTDIR"
    File test.exe
    CreateShortcut "$SMPROGRAMS\test.lnk" "$INSTDIR\Uninstall.exe"
    WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd

Section "Uninstall"
    RMDir /r "$INSTDIR"

    Delete "$SMPROGRAMS\test.lnk"
    MessageBox MB_OK "$SMPROGRAMS"
SectionEnd

The User can choose if he want to install it system wide (if he has Admin permission) or only for his own Account. The Installation itself works great, but not the Uninstall. If a User with Admin permission chooses to install into it's own account instead of system wide, it get's installed there. But if you try to uninstall it, $SMPROGRAMS will point to the System location instead of the User one, which does it not made work correctly.

Discussion

  • Anders

    Anders - 2022-10-31

    Try setting MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_KEY and MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_VALUENAME.

     
  • JakobDev

    JakobDev - 2022-11-08

    I added

    !define MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_KEY "Software/Testinstaller/Test"
    !define MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_VALUENAME "TestValue"
    

    above the MultiUser include, but it didn't change anything and I can't find anything in the Registry.

     
    • Anders

      Anders - 2022-11-12

      I guess you are responsible for writing. MultiUser will only read it.

      Name "Test"
      OutFile "Installer.exe"
      
      !define UNINSTKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp" ; TODO: Replace MyApp with a GUID
      !define UNINSTBIN "Uninstall.exe"
      !define MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_KEY ${UNINSTKEY}
      !define MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_VALUENAME "CurrentUser"
      
      !define MULTIUSER_INSTALLMODE_INSTDIR "$(^Name)"
      !define MULTIUSER_INSTALLMODE_COMMANDLINE
      !define MULTIUSER_EXECUTIONLEVEL Highest
      !define MULTIUSER_MUI
      
      !include "LogicLib.nsh"
      !include "MultiUser.nsh"
      !include "MUI2.nsh"
      
      !insertmacro MUI_PAGE_WELCOME
      !insertmacro MULTIUSER_PAGE_INSTALLMODE
      !insertmacro MUI_PAGE_DIRECTORY
      !insertmacro MUI_PAGE_INSTFILES
      !insertmacro MUI_PAGE_FINISH
      
      !insertmacro MUI_UNPAGE_CONFIRM
      !insertmacro MUI_UNPAGE_INSTFILES
      !insertmacro MUI_LANGUAGE "English"
      
      Function .onInit
          !insertmacro MULTIUSER_INIT
      FunctionEnd
      
      Function un.onInit
          !insertmacro MULTIUSER_UNINIT
      FunctionEnd
      
      Section 
      SetOutPath "$InstDir"
      WriteUninstaller "$INSTDIR\${UNINSTBIN}"
      WriteRegStr ShCtx "${UNINSTKEY}" DisplayName "$(^Name)"
      WriteRegStr ShCtx "${UNINSTKEY}" UninstallString '"$InstDir\${UNINSTBIN}"'
      WriteRegStr ShCtx "${UNINSTKEY}" $MultiUser.InstallMode 1
      MessageBox MB_OK "$SMPROGRAMS"
      SectionEnd
      
      Section "-Uninstall"
      MessageBox MB_OK "$SMPROGRAMS"
      DeleteRegKey ShCtx "${UNINSTKEY}"
      Delete "$INSTDIR\${UNINSTBIN}"
      RMDir $InstDir
      SectionEnd
      
       

      Last edit: Anders 2022-11-12

Log in to post a comment.

MongoDB Logo MongoDB