| 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 |
|
| 52 |
Section "Program files (Required)" |
| 53 |
SectionIn Ro |
| 54 |
|
| 55 |
SetOutPath $InstDir |
| 56 |
WriteUninstaller "$InstDir\Uninst.exe" |
| 57 |
WriteRegStr HKCU "${REGPATH_UNINSTSUBKEY}" "DisplayName" "${NAME}" |
| 58 |
WriteRegStr HKCU "${REGPATH_UNINSTSUBKEY}" "DisplayIcon" "$InstDir\MyApp.exe,0" |
| 59 |
WriteRegStr HKCU "${REGPATH_UNINSTSUBKEY}" "UninstallString" '"$InstDir\Uninst.exe"' |
| 60 |
WriteRegStr HKCU "${REGPATH_UNINSTSUBKEY}" "QuietUninstallString" '"$InstDir\Uninst.exe" /S' |
| 61 |
WriteRegDWORD HKCU "${REGPATH_UNINSTSUBKEY}" "NoModify" 1 |
| 62 |
WriteRegDWORD HKCU "${REGPATH_UNINSTSUBKEY}" "NoRepair" 1 |
| 63 |
|
| 64 |
!tempfile APP |
| 65 |
!makensis '-v2 "-DOUTFILE=${APP}" "-DNAME=NSISPerUserAppExample" -DCOMPANY=Nullsoft "AppGen.nsi"' = 0 |
| 66 |
File "/oname=$InstDir\MyApp.exe" "${APP}" ; Pretend that we have a real application to install |
| 67 |
!delfile "${APP}" |
| 68 |
SectionEnd |
| 69 |
|
| 70 |
Section "Start Menu shortcut" |
| 71 |
CreateShortcut /NoWorkingDir "$SMPrograms\${NAME}.lnk" "$InstDir\MyApp.exe" |
| 72 |
SectionEnd |
| 73 |
|
| 74 |
/* |
| 75 |
This Section registers a fictional .test-nullsoft file extension and the Nullsoft.Test ProgId. |
| 76 |
Proprietary file types are encouraged (by Microsoft) to use long file extensions and ProgIds that include the company name. |
| 77 |
|
| 78 |
When registering with "Open With" your executable should ideally have a somewhat unique name, |
| 79 |
otherwise there could be a naming collision with a different application (with the same name) installed on the same machine. |
| 80 |
|
| 81 |
REGISTER_DEFAULTPROGRAMS is not defined because proprietary file types do not typically use the Default Programs functionality. |
| 82 |
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. |
| 83 |
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). |
| 84 |
*/ |
| 85 |
!define ASSOC_EXT ".test-nullsoft" |
| 86 |
!define ASSOC_PROGID "Nullsoft.Test" |
| 87 |
!define ASSOC_VERB "MyApp" |
| 88 |
!define ASSOC_APPEXE "MyApp.exe" |
| 89 |
Section -ShellAssoc |
| 90 |
# Register file type |
| 91 |
WriteRegStr ShCtx "Software\Classes\${ASSOC_PROGID}\DefaultIcon" "" "$InstDir\${ASSOC_APPEXE},0" |
| 92 |
;WriteRegStr ShCtx "Software\Classes\${ASSOC_PROGID}\shell\${ASSOC_VERB}" "" "Nullsoft Test App" [Optional] |
| 93 |
;WriteRegStr ShCtx "Software\Classes\${ASSOC_PROGID}\shell\${ASSOC_VERB}" "MUIVerb" "@$InstDir\${ASSOC_APPEXE},-42" ; WinXP+ [Optional] Localizable verb display name |
| 94 |
WriteRegStr ShCtx "Software\Classes\${ASSOC_PROGID}\shell\${ASSOC_VERB}\command" "" '"$InstDir\${ASSOC_APPEXE}" "%1"' |
| 95 |
WriteRegStr ShCtx "Software\Classes\${ASSOC_EXT}" "" "${ASSOC_PROGID}" |
| 96 |
|
| 97 |
# Register "Open With" [Optional] |
| 98 |
WriteRegNone ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithList" "${ASSOC_APPEXE}" ; Win2000+ [Optional] |
| 99 |
;WriteRegNone ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithProgids" "${ASSOC_PROGID}" ; WinXP+ [Optional] |
| 100 |
WriteRegStr ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}\shell\open\command" "" '"$InstDir\${ASSOC_APPEXE}" "%1"' |
| 101 |
WriteRegStr ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}" "FriendlyAppName" "Nullsoft Test App" ; [Optional] |
| 102 |
WriteRegStr ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}" "ApplicationCompany" "Nullsoft" ; [Optional] |
| 103 |
WriteRegNone ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}\SupportedTypes" "${ASSOC_EXT}" ; [Optional] Only allow "Open With" with specific extension(s) on WinXP+ |
| 104 |
|
| 105 |
# Register "Default Programs" [Optional] |
| 106 |
!ifdef REGISTER_DEFAULTPROGRAMS |
| 107 |
WriteRegStr ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}\Capabilities" "ApplicationDescription" "Shell association example test application" |
| 108 |
WriteRegStr ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}\Capabilities\FileAssociations" "${ASSOC_EXT}" "${ASSOC_PROGID}" |
| 109 |
WriteRegStr ShCtx "Software\RegisteredApplications" "Nullsoft Test App" "Software\Classes\Applications\${ASSOC_APPEXE}\Capabilities" |
| 110 |
!endif |
| 111 |
|
| 112 |
${NotifyShell_AssocChanged} |
| 113 |
SectionEnd |
| 114 |
|
| 115 |
|
| 116 |
Section -un.ShellAssoc |
| 117 |
# Unregister file type |
| 118 |
ClearErrors |
| 119 |
DeleteRegKey ShCtx "Software\Classes\${ASSOC_PROGID}\shell\${ASSOC_VERB}" |
| 120 |
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_PROGID}\shell" |
| 121 |
${IfNot} ${Errors} |
| 122 |
DeleteRegKey ShCtx "Software\Classes\${ASSOC_PROGID}\DefaultIcon" |
| 123 |
${EndIf} |
| 124 |
ReadRegStr $0 ShCtx "Software\Classes\${ASSOC_EXT}" "" |
| 125 |
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_PROGID}" |
| 126 |
${IfNot} ${Errors} |
| 127 |
${AndIf} $0 == "${ASSOC_PROGID}" |
| 128 |
DeleteRegValue ShCtx "Software\Classes\${ASSOC_EXT}" "" |
| 129 |
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_EXT}" |
| 130 |
${EndIf} |
| 131 |
|
| 132 |
# Unregister "Open With" |
| 133 |
DeleteRegKey ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}" |
| 134 |
DeleteRegValue ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithList" "${ASSOC_APPEXE}" |
| 135 |
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithList" |
| 136 |
DeleteRegValue ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithProgids" "${ASSOC_PROGID}" |
| 137 |
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_EXT}\OpenWithProgids" |
| 138 |
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_EXT}" |
| 139 |
|
| 140 |
# Unregister "Default Programs" |
| 141 |
!ifdef REGISTER_DEFAULTPROGRAMS |
| 142 |
DeleteRegValue ShCtx "Software\RegisteredApplications" "Nullsoft Test App" |
| 143 |
DeleteRegKey ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}\Capabilities" |
| 144 |
DeleteRegKey /IfEmpty ShCtx "Software\Classes\Applications\${ASSOC_APPEXE}" |
| 145 |
!endif |
| 146 |
|
| 147 |
# Attempt to clean up junk left behind by the Windows shell |
| 148 |
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Search\JumplistData" "$InstDir\${ASSOC_APPEXE}" |
| 149 |
DeleteRegValue HKCU "Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache" "$InstDir\${ASSOC_APPEXE}.FriendlyAppName" |
| 150 |
DeleteRegValue HKCU "Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache" "$InstDir\${ASSOC_APPEXE}.ApplicationCompany" |
| 151 |
DeleteRegValue HKCU "Software\Microsoft\Windows\ShellNoRoam\MUICache" "$InstDir\${ASSOC_APPEXE}" ; WinXP |
| 152 |
DeleteRegValue HKCU "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store" "$InstDir\${ASSOC_APPEXE}" |
| 153 |
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts" "${ASSOC_PROGID}_${ASSOC_EXT}" |
| 154 |
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts" "Applications\${ASSOC_APPEXE}_${ASSOC_EXT}" |
| 155 |
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${ASSOC_EXT}\OpenWithProgids" "${ASSOC_PROGID}" |
| 156 |
DeleteRegKey /IfEmpty HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${ASSOC_EXT}\OpenWithProgids" |
| 157 |
DeleteRegKey /IfEmpty HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${ASSOC_EXT}\OpenWithList" |
| 158 |
DeleteRegKey /IfEmpty HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${ASSOC_EXT}" |
| 159 |
;DeleteRegKey HKCU "Software\Microsoft\Windows\Roaming\OpenWith\FileExts\${ASSOC_EXT}" |
| 160 |
;DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs\${ASSOC_EXT}" |
| 161 |
|
| 162 |
${NotifyShell_AssocChanged} |
| 163 |
SectionEnd |
| 164 |
|
| 165 |
!macro DeleteFileOrAskAbort path |
| 166 |
ClearErrors |
| 167 |
Delete "${path}" |
| 168 |
IfErrors 0 +3 |
| 169 |
MessageBox MB_ABORTRETRYIGNORE|MB_ICONSTOP 'Unable to delete "${path}"!' IDRETRY -3 IDIGNORE +2 |
| 170 |
Abort "Aborted" |
| 171 |
!macroend |
| 172 |
|
| 173 |
Section -Uninstall |
| 174 |
!insertmacro DeleteFileOrAskAbort "$InstDir\MyApp.exe" |
| 175 |
Delete "$InstDir\Uninst.exe" |
| 176 |
RMDir "$InstDir" |
| 177 |
DeleteRegKey HKCU "${REGPATH_UNINSTSUBKEY}" |
| 178 |
|
| 179 |
${UnpinShortcut} "$SMPrograms\${NAME}.lnk" |
| 180 |
Delete "$SMPrograms\${NAME}.lnk" |
| 181 |
SectionEnd |