MultiUser.nsi 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. Name "MultiUser example"
  2. OutFile "MultiUser.exe"
  3. !define UNINSTKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
  4. !define MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_KEY "${UNINSTKEY}"
  5. !define MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_VALUENAME "CurrentUser"
  6. !define MULTIUSER_INSTALLMODE_INSTDIR "$(^Name)"
  7. !define MULTIUSER_INSTALLMODE_COMMANDLINE
  8. !define MULTIUSER_EXECUTIONLEVEL Highest
  9. !define MULTIUSER_MUI
  10. !include "LogicLib.nsh"
  11. !include "MultiUser.nsh"
  12. !include "MUI2.nsh"
  13. !insertmacro MUI_PAGE_WELCOME
  14. !insertmacro MULTIUSER_PAGE_INSTALLMODE
  15. !insertmacro MUI_PAGE_DIRECTORY
  16. !insertmacro MUI_PAGE_INSTFILES
  17. !insertmacro MUI_PAGE_FINISH
  18. !insertmacro MUI_UNPAGE_CONFIRM
  19. !insertmacro MUI_UNPAGE_INSTFILES
  20. !insertmacro MUI_LANGUAGE "English"
  21. Function .onInit
  22. !insertmacro MULTIUSER_INIT
  23. FunctionEnd
  24. Function un.onInit
  25. !insertmacro MULTIUSER_UNINIT
  26. FunctionEnd
  27. Section
  28. SetOutPath "$InstDir"
  29. WriteUninstaller "$InstDir\Uninstall.exe"
  30. WriteRegStr ShCtx "${UNINSTKEY}" DisplayName "$(^Name)"
  31. WriteRegStr ShCtx "${UNINSTKEY}" UninstallString '"$InstDir\Uninstall.exe"'
  32. WriteRegStr ShCtx "${UNINSTKEY}" $MultiUser.InstallMode 1 ; Write MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_VALUENAME so the correct context can be detected in the uninstaller.
  33. !tempfile APP
  34. !makensis '-v2 "-DOUTFILE=${APP}" "-DNAME=NsisMultiUserExample" -DCOMPANY=Nullsoft "AppGen.nsi"' = 0
  35. File "/oname=$InstDir\MyApp.exe" "${APP}" ; Pretend that we have a real application to install
  36. !delfile "${APP}"
  37. SectionEnd
  38. Section "Start Menu shortcut"
  39. CreateShortcut /NoWorkingDir "$SMPrograms\$(^Name).lnk" "$InstDir\MyApp.exe"
  40. SectionEnd
  41. Section "-Uninstall"
  42. Delete "$SMPrograms\$(^Name).lnk"
  43. Delete "$InstDir\MyApp.exe"
  44. Delete "$InstDir\Uninstall.exe"
  45. DeleteRegKey ShCtx "${UNINSTKEY}"
  46. RMDir $InstDir
  47. SectionEnd