From 657a66f07107ff4df32fe631758dbd2fa7b8f4c7 Mon Sep 17 00:00:00 2001 From: anders_k Date: Tue, 17 Mar 2020 19:02:42 +0000 Subject: [PATCH] Added install-per-user.nsi example git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@7155 212acab6-be3b-0410-9dea-997c60f758d6 --- Docs/src/generalpurpose.but | 13 ++++-- Examples/SConscript | 1 + Examples/install-per-user.nsi | 78 +++++++++++++++++++++++++++++++++++ Examples/makensis.nsi | 1 + 4 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 Examples/install-per-user.nsi diff --git a/Docs/src/generalpurpose.but b/Docs/src/generalpurpose.but index 0cd01d39..47c3b142 100644 --- a/Docs/src/generalpurpose.but +++ b/Docs/src/generalpurpose.but @@ -88,9 +88,16 @@ This is similar to \R{getfiletime}{GetFileTime}, only it acts on the system buil Get the path of a \W{https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid}{known folder}. The error flag is set and the output variable is empty if the call fails or the knownfolderid guid is not available. This function is only able to resolve known folders Windows Vista or higher. \c !include WinCore.nsh -\c GetKnownFolderPath $InstDir ${FOLDERID_UserProgramFiles} -\c StrCmp $InstDir "" 0 +2 -\c StrCpy $InstDir "$LocalAppData\Programs" +\c !include LogicLib.nsh +\c +\c Function .onInit +\c ${If} $InstDir == "" +\c GetKnownFolderPath $InstDir ${FOLDERID_UserProgramFiles} ; This exists on Win7+ +\c StrCmp $InstDir "" 0 +2 +\c StrCpy $InstDir "$LocalAppData\Programs" ; Fallback directory +\c StrCpy $InstDir "$InstDir\$(^Name)" +\c ${EndIf} +\c FunctionEnd \S2{getfullpathname} GetFullPathName diff --git a/Examples/SConscript b/Examples/SConscript index c9a212e3..c1c226ae 100644 --- a/Examples/SConscript +++ b/Examples/SConscript @@ -6,6 +6,7 @@ examples = Split(""" FileFunc.nsi FileFuncTest.nsi gfx.nsi + install-per-user.nsi languages.nsi Library.nsi LogicLib.nsi diff --git a/Examples/install-per-user.nsi b/Examples/install-per-user.nsi new file mode 100644 index 00000000..f119b004 --- /dev/null +++ b/Examples/install-per-user.nsi @@ -0,0 +1,78 @@ +/* + +This example script installs a simple application for a single user. + +If multiple users on the same machine run this installer, each user +will end up with a separate install that is not affected by +update/removal operations performed by other users. + +Per-user installers should only write to HKCU and +folders inside the users profile. + +*/ + +!define NAME "Per-User example" +!define REGPATH_UNINSTSUBKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}" +Name "${NAME}" +OutFile "${NAME}.exe" +Unicode True +RequestExecutionLevel User ; We don't need UAC elevation +InstallDir "" ; Don't set a default $InstDir so we can detect /D= and InstallDirRegKey +InstallDirRegKey HKCU "${REGPATH_UNINSTSUBKEY}" "UninstallString" + +!include LogicLib.nsh +!include WinCore.nsh + + +Page Directory +Page InstFiles + +Uninstpage UninstConfirm +Uninstpage InstFiles + + +Function .onInit + SetShellVarContext Current + + ${If} $InstDir == "" ; No /D= nor InstallDirRegKey? + GetKnownFolderPath $InstDir ${FOLDERID_UserProgramFiles} ; This folder only exists on Win7+ + StrCmp $InstDir "" 0 +2 + StrCpy $InstDir "$LocalAppData\Programs" ; Fallback directory + + StrCpy $InstDir "$InstDir\$(^Name)" + ${EndIf} +FunctionEnd + + +Section "Program files (Required)" + SectionIn Ro + + SetOutPath $InstDir + WriteUninstaller "$InstDir\Uninst.exe" + WriteRegStr HKCU "${REGPATH_UNINSTSUBKEY}" "DisplayName" "${NAME}" + WriteRegStr HKCU "${REGPATH_UNINSTSUBKEY}" "UninstallString" '"$InstDir\Uninst.exe"' + WriteRegDWORD HKCU "${REGPATH_UNINSTSUBKEY}" "NoModify" 1 + WriteRegDWORD HKCU "${REGPATH_UNINSTSUBKEY}" "NoRepair" 1 + + File "/oname=$InstDir\MyApp.exe" "${NSISDIR}\Bin\MakeLangId.exe" ; Pretend that we have a real application to install + + ;WriteRegStr HKCU "Software\Classes\.myfileext" "myfiletype" + ;WriteRegStr HKCU "Software\Classes\myfiletype\shell\myapp\command" "" '"$InstDir\MyApp.exe" "%1"' +SectionEnd + +Section "Start Menu shortcut" + CreateShortcut /NoWorkingDir "$SMPrograms\${NAME}.lnk" "$InstDir\MyApp.exe" +SectionEnd + + +Section -Uninstall + Delete "$InstDir\MyApp.exe" + Delete "$InstDir\Uninst.exe" + RMDir "$InstDir" + DeleteRegKey HKCU "${REGPATH_UNINSTSUBKEY}" + ;DeleteRegKey HKCU "Software\Classes\myfiletype\shell\myapp" + ;DeleteRegKey /IfEmpty HKCU "Software\Classes\myfiletype\shell" + ;DeleteRegKey /IfEmpty HKCU "Software\Classes\myfiletype" + + Delete "$SMPrograms\${NAME}.lnk" +SectionEnd diff --git a/Examples/makensis.nsi b/Examples/makensis.nsi index 30d20745..9a90c924 100644 --- a/Examples/makensis.nsi +++ b/Examples/makensis.nsi @@ -311,6 +311,7 @@ ${MementoSection} "Script Examples" SecExample File ..\Examples\makensis.nsi File ..\Examples\example1.nsi File ..\Examples\example2.nsi + File ..\Examples\install-per-user.nsi File ..\Examples\viewhtml.nsi File ..\Examples\waplugin.nsi File ..\Examples\bigtest.nsi