Statistiques
| Révision :

root / tmp / org.txm.setups / nsis / Examples / install-per-user.nsi @ 3144

Historique | Voir | Annoter | Télécharger (8,29 ko)

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