install-shared.nsi 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. This example script installs a simple application for all users on a machine.
  3. All-users installers should only write to HKLM, $ProgramFiles, $CommonFiles and the
  4. "All context" versions of $LocalAppData, $Templates, $SMPrograms etc.
  5. It should not write to HKCU nor any folders in the users profile!
  6. If the application requires writable template data in $AppData it
  7. must copy the required files from a shared location the
  8. first time a user launches the application.
  9. */
  10. !define NAME "All-users example"
  11. !define REGPATH_UNINSTSUBKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}"
  12. Name "${NAME}"
  13. OutFile "Install ${NAME}.exe"
  14. Unicode True
  15. RequestExecutionLevel Admin ; Request admin rights on WinVista+ (when UAC is turned on)
  16. InstallDir "$ProgramFiles\$(^Name)"
  17. InstallDirRegKey HKLM "${REGPATH_UNINSTSUBKEY}" "UninstallString"
  18. !include LogicLib.nsh
  19. !include Integration.nsh
  20. Page Directory
  21. Page InstFiles
  22. Uninstpage UninstConfirm
  23. Uninstpage InstFiles
  24. !macro EnsureAdminRights
  25. UserInfo::GetAccountType
  26. Pop $0
  27. ${If} $0 != "admin" ; Require admin rights on WinNT4+
  28. MessageBox MB_IconStop "Administrator rights required!"
  29. SetErrorLevel 740 ; ERROR_ELEVATION_REQUIRED
  30. Quit
  31. ${EndIf}
  32. !macroend
  33. Function .onInit
  34. SetShellVarContext All
  35. !insertmacro EnsureAdminRights
  36. FunctionEnd
  37. Function un.onInit
  38. SetShellVarContext All
  39. !insertmacro EnsureAdminRights
  40. FunctionEnd
  41. Section "Program files (Required)"
  42. SectionIn Ro
  43. SetOutPath $InstDir
  44. WriteUninstaller "$InstDir\Uninst.exe"
  45. WriteRegStr HKLM "${REGPATH_UNINSTSUBKEY}" "DisplayName" "${NAME}"
  46. WriteRegStr HKLM "${REGPATH_UNINSTSUBKEY}" "DisplayIcon" "$InstDir\MyApp.exe,0"
  47. WriteRegStr HKLM "${REGPATH_UNINSTSUBKEY}" "UninstallString" '"$InstDir\Uninst.exe"'
  48. WriteRegStr HKLM "${REGPATH_UNINSTSUBKEY}" "QuietUninstallString" '"$InstDir\Uninst.exe" /S'
  49. WriteRegDWORD HKLM "${REGPATH_UNINSTSUBKEY}" "NoModify" 1
  50. WriteRegDWORD HKLM "${REGPATH_UNINSTSUBKEY}" "NoRepair" 1
  51. !tempfile APP
  52. !makensis '-v2 "-DOUTFILE=${APP}" "-DNAME=NSISSharedAppExample" -DCOMPANY=Nullsoft "AppGen.nsi"' = 0
  53. File "/oname=$InstDir\MyApp.exe" "${APP}" ; Pretend that we have a real application to install
  54. !delfile "${APP}"
  55. SectionEnd
  56. Section "Start Menu shortcut"
  57. CreateShortcut /NoWorkingDir "$SMPrograms\${NAME}.lnk" "$InstDir\MyApp.exe"
  58. SectionEnd
  59. !macro DeleteFileOrAskAbort path
  60. ClearErrors
  61. Delete "${path}"
  62. IfErrors 0 +3
  63. MessageBox MB_ABORTRETRYIGNORE|MB_ICONSTOP 'Unable to delete "${path}"!' IDRETRY -3 IDIGNORE +2
  64. Abort "Aborted"
  65. !macroend
  66. Section -Uninstall
  67. !insertmacro DeleteFileOrAskAbort "$InstDir\MyApp.exe"
  68. Delete "$InstDir\Uninst.exe"
  69. RMDir "$InstDir"
  70. DeleteRegKey HKLM "${REGPATH_UNINSTSUBKEY}"
  71. ${UnpinShortcut} "$SMPrograms\${NAME}.lnk"
  72. Delete "$SMPrograms\${NAME}.lnk"
  73. SectionEnd