Debian Codegraph @

Examples/install-shared.nsi

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