Skip to content

Commit

Permalink
fix(nsis): machine-wide boring NSIS installer launches application as…
Browse files Browse the repository at this point in the history
… administrator

Closes #864
  • Loading branch information
develar committed Nov 3, 2016
1 parent cf24b01 commit 7ea3d62
Showing 6 changed files with 46 additions and 42 deletions.
21 changes: 13 additions & 8 deletions templates/nsis/boringInstaller.nsh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
!include UAC.nsh
!include StdUtils.nsh

!ifndef INSTALL_MODE_PER_ALL_USERS
!include multiUserUi.nsh
!endif

!ifndef BUILD_UNINSTALLER
Function StartApp
!insertmacro UAC_AsUser_ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "" "" ""
${StdUtils.ExecShellAsUser} $0 "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "open" ""
FunctionEnd

!define MUI_FINISHPAGE_RUN
@@ -41,10 +42,14 @@
!insertmacro UAC_PageElevation_OnInit

${If} ${UAC_IsInnerInstance}
${AndIfNot} ${UAC_IsAdmin}
# special return value for outer instance so it knows we did not have admin rights
SetErrorLevel 0x666666
Quit
${If} ${UAC_IsAdmin}
!insertmacro setInstallModePerAllUsers
Goto functionEnd
${else}
# special return value for outer instance so it knows we did not have admin rights
SetErrorLevel 0x666666
Quit
${EndIf}
${EndIf}

!ifndef MULTIUSER_INIT_TEXT_ADMINREQUIRED
@@ -78,13 +83,13 @@
${GetOptions} $R0 "/allusers" $R1
${IfNot} ${Errors}
!insertmacro setInstallModePerAllUsers
Goto FEnd
Goto functionEnd
${EndIf}

${GetOptions} $R0 "/currentuser" $R1
${IfNot} ${Errors}
!insertmacro setInstallModePerUser
Goto FEnd
Goto functionEnd
${EndIf}

${if} $hasPerUserInstallation == "1"
@@ -102,7 +107,7 @@
!endif
${endif}

FEnd:
functionEnd:
!endif
!macroend

27 changes: 27 additions & 0 deletions templates/nsis/installSection.nsh
Original file line number Diff line number Diff line change
@@ -43,6 +43,33 @@
${endif}
!macroend

!macro registryAddInstallInfo
WriteRegStr SHCTX "${INSTALL_REGISTRY_KEY}" InstallLocation "$INSTDIR"

${if} $installMode == "all"
StrCpy $0 "/allusers"
StrCpy $1 ""
${else}
StrCpy $0 "/currentuser"
StrCpy $1 " (only current user)"
${endif}

WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" DisplayName "${UNINSTALL_DISPLAY_NAME}$1"
# https://github.com/electron-userland/electron-builder/issues/750
StrCpy $2 "$INSTDIR\${UNINSTALL_FILENAME}"
WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" UninstallString '"$2" $0'

WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" "DisplayVersion" "${VERSION}"
WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" "DisplayIcon" "$appExe,0"
WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" "Publisher" "${COMPANY_NAME}"
WriteRegDWORD SHCTX "${UNINSTALL_REGISTRY_KEY}" NoModify 1
WriteRegDWORD SHCTX "${UNINSTALL_REGISTRY_KEY}" NoRepair 1

${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0
WriteRegDWORD SHCTX "${UNINSTALL_REGISTRY_KEY}" "EstimatedSize" "$0"
!macroend

InitPluginsDir

!ifdef HEADER_ICO
3 changes: 2 additions & 1 deletion templates/nsis/installer.nsi
Original file line number Diff line number Diff line change
@@ -38,7 +38,6 @@ Function .onInit
!insertmacro quitSuccess
!else
!insertmacro check64BitAndSetRegView
!insertmacro initMultiUser

!ifdef ONE_CLICK
!insertmacro ALLOW_ONLY_ONE_INSTALLER_INSTANCE
@@ -48,6 +47,8 @@ Function .onInit
${EndIf}
!endif

!insertmacro initMultiUser

!ifmacrodef customInit
!insertmacro customInit
!endif
30 changes: 1 addition & 29 deletions templates/nsis/multiUser.nsh
Original file line number Diff line number Diff line change
@@ -59,32 +59,4 @@ Var installMode
${endif}
!endif
!macroend
!endif

# SHCTX is the hive HKLM if SetShellVarContext all, or HKCU if SetShellVarContext user
!macro registryAddInstallInfo
WriteRegStr SHCTX "${INSTALL_REGISTRY_KEY}" InstallLocation "$INSTDIR"

${if} $installMode == "all"
StrCpy $0 "/allusers"
StrCpy $1 ""
${else}
StrCpy $0 "/currentuser"
StrCpy $1 " (only current user)"
${endif}

WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" DisplayName "${UNINSTALL_DISPLAY_NAME}$1"
# https://github.com/electron-userland/electron-builder/issues/750
StrCpy $2 "$INSTDIR\${UNINSTALL_FILENAME}"
WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" UninstallString '"$2" $0'

WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" "DisplayVersion" "${VERSION}"
WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" "DisplayIcon" "$appExe,0"
WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" "Publisher" "${COMPANY_NAME}"
WriteRegDWORD SHCTX "${UNINSTALL_REGISTRY_KEY}" NoModify 1
WriteRegDWORD SHCTX "${UNINSTALL_REGISTRY_KEY}" NoRepair 1

${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0
WriteRegDWORD SHCTX "${UNINSTALL_REGISTRY_KEY}" "EstimatedSize" "$0"
!macroend
!endif
5 changes: 2 additions & 3 deletions templates/nsis/multiUserUi.nsh
Original file line number Diff line number Diff line change
@@ -126,9 +126,8 @@ Var RadioButtonLabel1
SendMessage $MultiUser.InstallModePage.AllUsers ${BM_GETCHECK} 0 0 $MultiUser.InstallModePage.ReturnValue

${if} $MultiUser.InstallModePage.ReturnValue = ${BST_CHECKED}
${if} ${UAC_IsAdmin}
!insertmacro setInstallModePerAllUsers
${else}
!insertmacro setInstallModePerAllUsers
${IfNot} ${UAC_IsAdmin}
!ifdef MULTIUSER_INSTALLMODE_ALLOW_ELEVATION
GetDlgItem $9 $HWNDParent 1
System::Call user32::GetFocus()i.s
2 changes: 1 addition & 1 deletion templates/nsis/oneClick.nsh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
!ifdef RUN_AFTER_FINISH
!ifndef BUILD_UNINSTALLER
!include StdUtils.nsh
Function StartApp
!ifdef INSTALL_MODE_PER_ALL_USERS
!include StdUtils.nsh
${StdUtils.ExecShellAsUser} $0 "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "open" ""
!else
ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk"

0 comments on commit 7ea3d62

Please sign in to comment.