root / tmp / org.txm.setups / nsis / Examples / install-per-user.nsi @ 3092
Historique | Voir | Annoter | Télécharger (8,29 ko)
1 |
/* |
---|---|
2 |
|
3 |
This example script installs a simple application for a single user. |
4 |
|
5 |
If multiple users on the same machine run this installer, each user |
6 |
will end up with a separate install that is not affected by |
7 |
update/removal operations performed by other users. |
8 |
|
9 |
Per-user installers should only write to HKCU and |
10 |
folders inside the users profile. |
11 |
|
12 |
*/ |
13 |
|
14 |
!define NAME "Per-User example" |
15 |
!define REGPATH_UNINSTSUBKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}" |
16 |
Name "${NAME}" |
17 |
OutFile "Install ${NAME}.exe" |
18 |
Unicode True |
19 |
RequestExecutionLevel User ; We don't need UAC elevation |
20 |
InstallDir "" ; Don't set a default $InstDir so we can detect /D= and InstallDirRegKey |
21 |
InstallDirRegKey HKCU "${REGPATH_UNINSTSUBKEY}" "UninstallString" |
22 |
|
23 |
!include LogicLib.nsh |
24 |
!include WinCore.nsh |
25 |
!include Integration.nsh |
26 |
|
27 |
|
28 |
Page Directory |
29 |
Page InstFiles |
30 |
|
31 |
Uninstpage UninstConfirm |
32 |
Uninstpage InstFiles |
33 |
|
34 |
|
35 |
Function .onInit |
36 |
SetShellVarContext Current |
37 |
|
38 |
${If} $InstDir == "" ; No /D= nor InstallDirRegKey? |
39 |
GetKnownFolderPath $InstDir ${FOLDERID_UserProgramFiles} ; This folder only exists on Win7+ |
40 |
StrCmp $InstDir "" 0 +2 |
41 |
StrCpy $InstDir "$LocalAppData\Programs" ; Fallback directory |
42 |
|
43 |
StrCpy $InstDir "$InstDir\$(^Name)" |
44 |
${EndIf} |
45 |
FunctionEnd |
46 |
|
47 |
Function un.onInit |
48 |
SetShellVarContext Current |
49 |
FunctionEnd |
50 |
|
51 |
Section "Program files (Required)" |
52 |
SectionIn Ro |
53 |
|
54 |
SetOutPath $InstDir |
55 |
WriteUninstaller "$InstDir\Uninst.exe" |
56 |
WriteRegStr HKCU "${REGPATH_UNINSTSUBKEY}" "DisplayName" "${NAME}" |
57 |
WriteRegStr HKCU "${REGPATH_UNINSTSUBKEY}" "DisplayIcon" "$InstDir\MyApp.exe,0" |
58 |
WriteRegStr HKCU "${REGPATH_UNINSTSUBKEY}" "UninstallString" '"$InstDir\Uninst.exe"' |
59 |
WriteRegDWORD HKCU "${REGPATH_UNINSTSUBKEY}" "NoModify" 1 |
60 |
WriteRegDWORD HKCU "${REGPATH_UNINSTSUBKEY}" "NoRepair" 1 |
61 |
|
62 |
File "/oname=$InstDir\MyApp.exe" "${NSISDIR}\Bin\MakeLangId.exe" ; Pretend that we have a real application to install |
63 |
SectionEnd |
64 |
|
65 |
Section "Start Menu shortcut" |
66 |
CreateShortcut /NoWorkingDir "$SMPrograms\${NAME}.lnk" "$InstDir\MyApp.exe" |
67 |
SectionEnd |
68 |
|
69 |
/* |
70 |
This Section registers a fictional .test-nullsoft file extension and the Nullsoft.Test ProgId. |
71 |
Proprietary file types are encouraged (by Microsoft) to use long file extensions and ProgIds that include the company name. |
72 |
|
73 |
When registering with "Open With" your executable should ideally have a somewhat unique name, |
74 |
otherwise there could be a naming collision with a different application (with the same name) installed on the same machine. |
75 |
|
76 |
REGISTER_DEFAULTPROGRAMS is not defined because proprietary file types do not typically use the Default Programs functionality. |
77 |
If your application registers a standard file type such as .mp3 or .html or a protocol like HTTP it should register as a Default Program. |
78 |
It should also register as a client (https://docs.microsoft.com/en-us/windows/win32/shell/reg-middleware-apps#common-registration-elements-for-all-client-types). |
79 |
*/ |
80 |
!define ASSOC_EXT ".test-nullsoft" |
81 |
!define ASSOC_PROGID "Nullsoft.Test" |
82 |
!define ASSOC_VERB "MyApp" |
83 |
!define ASSOC_APPEXE "MyApp.exe" |
84 |
Section -ShellAssoc |
85 |
# Register file type |
86 |
WriteRegStr ShCtx "Software\Classes\${ASSOC_PROGID}\DefaultIcon" "" "$InstDir\${ASSOC_APPEXE},0" |
87 |
;WriteRegStr ShCtx "Software\Classes\${ASSOC_PROGID}\shell\${ASSOC_VERB}" "" "Nullsoft Test App" [Optional] |
88 |
;WriteRegStr ShCtx "Software\Classes\${ASSOC_PROGID}\shell\${ASSOC_VERB}" "MUIVerb" "@$InstDir\${ASSOC_APPEXE},-42" ; WinXP+ [Optional] Localizable verb display name |
89 |
WriteRegStr ShCtx "Software\Classes\${ASSOC_PROGID}\shell\${ASSOC_VERB}\command" "" '"$InstDir\${ASSOC_APPEXE}" "%1"' |
90 |
WriteRegStr ShCtx "Software\Classes\${ASSOC_EXT}" "" "${ASSOC_PROGID}" |
91 |
|
92 |
# Register "Open With" [Optional] |
93 |
WriteRegNone ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithList" "${ASSOC_APPEXE}" ; Win2000+ [Optional] |
94 |
;WriteRegNone ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithProgids" "${ASSOC_PROGID}" ; WinXP+ [Optional] |
95 |
WriteRegStr ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}\shell\open\command" "" '"$InstDir\${ASSOC_APPEXE}" "%1"' |
96 |
WriteRegStr ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}" "FriendlyAppName" "Nullsoft Test App" ; [Optional] |
97 |
WriteRegStr ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}" "ApplicationCompany" "Nullsoft" ; [Optional] |
98 |
WriteRegNone ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}\SupportedTypes" "${ASSOC_EXT}" ; [Optional] Only allow "Open With" with specific extension(s) on WinXP+ |
99 |
|
100 |
# Register "Default Programs" [Optional] |
101 |
!ifdef REGISTER_DEFAULTPROGRAMS |
102 |
WriteRegStr ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}\Capabilities" "ApplicationDescription" "Shell association example test application" |
103 |
WriteRegStr ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}\Capabilities\FileAssociations" "${ASSOC_EXT}" "${ASSOC_PROGID}" |
104 |
WriteRegStr ShCtx "Software\RegisteredApplications" "Nullsoft Test App" "Software\Classes\Applications\${ASSOC_APPEXE}\Capabilities" |
105 |
!endif |
106 |
|
107 |
${NotifyShell_AssocChanged} |
108 |
SectionEnd |
109 |
|
110 |
|
111 |
Section -un.ShellAssoc |
112 |
# Unregister file type |
113 |
ClearErrors |
114 |
DeleteRegKey ShCtx "Software\Classes\${ASSOC_PROGID}\shell\${ASSOC_VERB}" |
115 |
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_PROGID}\shell" |
116 |
${IfNot} ${Errors} |
117 |
DeleteRegKey ShCtx "Software\Classes\${ASSOC_PROGID}\DefaultIcon" |
118 |
${EndIf} |
119 |
ReadRegStr $0 ShCtx "Software\Classes\${ASSOC_EXT}" "" |
120 |
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_PROGID}" |
121 |
${IfNot} ${Errors} |
122 |
${AndIf} $0 == "${ASSOC_PROGID}" |
123 |
DeleteRegValue ShCtx "Software\Classes\${ASSOC_EXT}" "" |
124 |
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_EXT}" |
125 |
${EndIf} |
126 |
|
127 |
# Unregister "Open With" |
128 |
DeleteRegKey ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}" |
129 |
DeleteRegValue ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithList" "${ASSOC_APPEXE}" |
130 |
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithList" |
131 |
DeleteRegValue ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithProgids" "${ASSOC_PROGID}" |
132 |
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithProgids" |
133 |
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_EXT}" |
134 |
|
135 |
# Unregister "Default Programs" |
136 |
!ifdef REGISTER_DEFAULTPROGRAMS |
137 |
DeleteRegValue ShCtx "Software\RegisteredApplications" "Nullsoft Test App" |
138 |
DeleteRegKey ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}\Capabilities" |
139 |
DeleteRegKey /IfEmpty ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}" |
140 |
!endif |
141 |
|
142 |
# Attempt to clean up junk left behind by the Windows shell |
143 |
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Search\JumplistData" "$InstDir\${ASSOC_APPEXE}" |
144 |
DeleteRegValue HKCU "Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache" "$InstDir\${ASSOC_APPEXE}.FriendlyAppName" |
145 |
DeleteRegValue HKCU "Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache" "$InstDir\${ASSOC_APPEXE}.ApplicationCompany" |
146 |
DeleteRegValue HKCU "Software\Microsoft\Windows\ShellNoRoam\MUICache" "$InstDir\${ASSOC_APPEXE}" ; WinXP |
147 |
DeleteRegValue HKCU "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store" "$InstDir\${ASSOC_APPEXE}" |
148 |
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts" "${ASSOC_PROGID}_${ASSOC_EXT}" |
149 |
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts" "Applications\${ASSOC_APPEXE}_${ASSOC_EXT}" |
150 |
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${ASSOC_EXT}\OpenWithProgids" "${ASSOC_PROGID}" |
151 |
DeleteRegKey /IfEmpty HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${ASSOC_EXT}\OpenWithProgids" |
152 |
DeleteRegKey /IfEmpty HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${ASSOC_EXT}\OpenWithList" |
153 |
DeleteRegKey /IfEmpty HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${ASSOC_EXT}" |
154 |
;DeleteRegKey HKCU "Software\Microsoft\Windows\Roaming\OpenWith\FileExts\${ASSOC_EXT}" |
155 |
;DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs\${ASSOC_EXT}" |
156 |
|
157 |
${NotifyShell_AssocChanged} |
158 |
SectionEnd |
159 |
|
160 |
Section -Uninstall |
161 |
${UnpinShortcut} "$SMPrograms\${NAME}.lnk" |
162 |
Delete "$SMPrograms\${NAME}.lnk" |
163 |
|
164 |
Delete "$InstDir\MyApp.exe" |
165 |
Delete "$InstDir\Uninst.exe" |
166 |
RMDir "$InstDir" |
167 |
DeleteRegKey HKCU "${REGPATH_UNINSTSUBKEY}" |
168 |
SectionEnd |