From 60876d63627422a1d060c71a4a5f13be33edf44f Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 16 Aug 2023 23:12:16 -0700 Subject: windows: don't require admin privilege. * inst.nsi (RequestExecutionLevel): Use the value "highest" instead of "admin", so that privilege is required for users that have it, otherwise not. (AccountType): New variable. (.onInit): Obtain the account type and store it in AccountType. Default the installation directory to $LOCALAPPDATA. If the user is admin, change the default to the appropriate Program Files directory. (TXR): If the user isn't admin, add TXR to the current user's PATH rather than the system PATH for everyone. (Uninstall): Remove TXR from the appropriate PATH. --- inst.nsi | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/inst.nsi b/inst.nsi index ae3e4d07..262f2eb8 100644 --- a/inst.nsi +++ b/inst.nsi @@ -10,11 +10,18 @@ UninstallIcon "win\txr.ico" SetCompressor lzma CRCCheck on -RequestExecutionLevel admin + +RequestExecutionLevel highest + +var AccountType Function .onInit - # default installation dir - StrCpy $INSTDIR "C:\Program Files" + StrCpy $INSTDIR "$LOCALAPPDATA" + UserInfo::GetAccountType + Pop $AccountType + ${If} $AccountType == "Admin" + StrCpy $INSTDIR "$PROGRAMFILES32" + ${EndIf} FunctionEnd Function .onInstSuccess @@ -71,7 +78,11 @@ section "TXR" CreateShortCut "$SMPROGRAMS\txr\uninstall.lnk" "$INSTDIR\txr\uninstall.exe" CreateShortCut "$SMPROGRAMS\txr\install-root.lnk" "$INSTDIR\txr" CreateShortCut "$STARTMENU\txr.lnk" "$INSTDIR\txr\bin\txr.exe" - ${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$INSTDIR\txr\bin" + ${If} $AccountType == "Admin" + ${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$INSTDIR\txr\bin" + ${Else} + ${EnvVarUpdate} $0 "PATH" "A" "HKCU" "$INSTDIR\txr\bin" + ${Endif} ${RegisterExtension} "$INSTDIR\txr\bin\txr-win.exe" ".txr" "TXR Pattern Language" ${RegisterExtension} "$INSTDIR\txr\bin\txr-win.exe" ".tl" "TXR Lisp" ${RegisterExtension} "$INSTDIR\txr\bin\txr-win.exe" ".tlo" "Compiled TXR Lisp" @@ -82,7 +93,11 @@ section "Uninstall" # $INSTDIR is now where the uninstaller is installed, # not the $INSTDIR that was used during installation! - ${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$INSTDIR\bin" + ${If} $AccountType == "Admin" + ${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$INSTDIR\bin" + ${Else} + ${un.EnvVarUpdate} $0 "PATH" "R" "HKCU" "$INSTDIR\bin" + ${Endif} ${UnregisterExtension} ".txr" "TXR Pattern Language" ${UnregisterExtension} ".tl" "TXR Lisp" ${UnregisterExtension} ".tlo" "Compiled TXR Lisp" -- cgit v1.2.3