root / tmp / org.txm.setups / nsis / Examples / install-shared.nsi @ 2961
Historique | Voir | Annoter | Télécharger (2,4 ko)
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 |
Page Directory |
28 |
Page InstFiles |
29 |
|
30 |
Uninstpage UninstConfirm |
31 |
Uninstpage InstFiles |
32 |
|
33 |
!macro EnsureAdminRights |
34 |
UserInfo::GetAccountType |
35 |
Pop $0 |
36 |
${If} $0 != "admin" ; Require admin rights on WinNT4+ |
37 |
MessageBox MB_IconStop "Administrator rights required!" |
38 |
SetErrorLevel 740 ; ERROR_ELEVATION_REQUIRED |
39 |
Quit |
40 |
${EndIf} |
41 |
!macroend |
42 |
|
43 |
Function .onInit |
44 |
SetShellVarContext All |
45 |
!insertmacro EnsureAdminRights |
46 |
FunctionEnd |
47 |
|
48 |
Function un.onInit |
49 |
SetShellVarContext All |
50 |
!insertmacro EnsureAdminRights |
51 |
FunctionEnd |
52 |
|
53 |
|
54 |
Section "Program files (Required)" |
55 |
SectionIn Ro |
56 |
|
57 |
SetOutPath $InstDir |
58 |
WriteUninstaller "$InstDir\Uninst.exe" |
59 |
WriteRegStr HKLM "${REGPATH_UNINSTSUBKEY}" "DisplayName" "${NAME}" |
60 |
WriteRegStr HKLM "${REGPATH_UNINSTSUBKEY}" "DisplayIcon" "$InstDir\MyApp.exe,0" |
61 |
WriteRegStr HKLM "${REGPATH_UNINSTSUBKEY}" "UninstallString" '"$InstDir\Uninst.exe"' |
62 |
WriteRegDWORD HKLM "${REGPATH_UNINSTSUBKEY}" "NoModify" 1 |
63 |
WriteRegDWORD HKLM "${REGPATH_UNINSTSUBKEY}" "NoRepair" 1 |
64 |
|
65 |
File "/oname=$InstDir\MyApp.exe" "${NSISDIR}\Bin\MakeLangId.exe" ; Pretend that we have a real application to install |
66 |
SectionEnd |
67 |
|
68 |
Section "Start Menu shortcut" |
69 |
CreateShortcut /NoWorkingDir "$SMPrograms\${NAME}.lnk" "$InstDir\MyApp.exe" |
70 |
SectionEnd |
71 |
|
72 |
|
73 |
Section -Uninstall |
74 |
${UnpinShortcut} "$SMPrograms\${NAME}.lnk" |
75 |
Delete "$SMPrograms\${NAME}.lnk" |
76 |
|
77 |
Delete "$InstDir\MyApp.exe" |
78 |
Delete "$InstDir\Uninst.exe" |
79 |
RMDir "$InstDir" |
80 |
DeleteRegKey HKLM "${REGPATH_UNINSTSUBKEY}" |
81 |
SectionEnd |