Fix #6169: Windows installer runs game with admin privileges (#6171)

This commit is contained in:
Richard Jenkins 2017-08-13 01:37:40 +01:00 committed by Ted John
parent 85c89481a5
commit d84db2d463
2 changed files with 46 additions and 2 deletions

View File

@ -57,7 +57,7 @@ CRCCheck force
ShowInstDetails show
ShowUninstDetails show
RequestExecutionLevel admin
RequestExecutionLevel user
Var SHORTCUTS
@ -66,6 +66,7 @@ Var SHORTCUTS
!include "InstallOptions.nsh"
!include "WinVer.nsh"
!include "x64.nsh"
!include "UAC.nsh"
!define MUI_ABORTWARNING
!define MUI_WELCOMEPAGE_TITLE_3LINES
@ -91,7 +92,8 @@ ManifestDPIAware true
!define MUI_FINISHPAGE_TITLE_3LINES
!define MUI_FINISHPAGE_RUN_TEXT "Run ${APPNAMEANDVERSION} now!"
!define MUI_FINISHPAGE_RUN "$INSTDIR\${OPENRCT2_EXE}"
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION PageFinishRun
!define MUI_FINISHPAGE_LINK "Visit the OpenRCT2 site for more information"
!define MUI_FINISHPAGE_LINK_LOCATION "${APPURLLINK}"
!define MUI_FINISHPAGE_NOREBOOTSUPPORT
@ -108,6 +110,35 @@ ManifestDPIAware true
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_RESERVEFILE_LANGDLL
!macro Init thing
uac_tryagain:
!insertmacro UAC_RunElevated
${Switch} $0
${Case} 0
${IfThen} $1 = 1 ${|} Quit ${|} ;we are the outer process, the inner process has done its work, we are done
${IfThen} $3 <> 0 ${|} ${Break} ${|} ;we are admin, let the show go on
${If} $1 = 3 ;RunAs completed successfully, but with a non-admin user
MessageBox mb_YesNo|mb_IconExclamation|mb_TopMost|mb_SetForeground "This ${thing} requires admin privileges, try again" /SD IDNO IDYES uac_tryagain IDNO 0
${EndIf}
;fall-through and die
${Case} 1223
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "This ${thing} requires admin privileges, aborting!"
Quit
${Case} 1062
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Logon service not running, aborting!"
Quit
${Default}
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Unable to elevate, error $0"
Quit
${EndSwitch}
SetShellVarContext all
!macroend
Function PageFinishRun
!insertmacro UAC_AsUser_ExecShell "" "$INSTDIR\${OPENRCT2_EXE}" "" "" ""
FunctionEnd
;--------------------------------------------------------------
; (Core) OpenRCT2 install section. Copies all internal game data
Section "!OpenRCT2" Section1
@ -454,6 +485,7 @@ Var UninstallString
;-----------------------------------------------------------------------------------
; NSIS Initialize function, determine if we are going to install/upgrade or uninstall
Function .onInit
!insertmacro Init "installer"
StrCpy $SHORTCUTS "OpenRCT2"
SectionSetFlags 0 17
@ -475,4 +507,8 @@ FinishCallback:
; Call CheckProcessorArchitecture
; Call CheckWindowsVersion
FunctionEnd
Function un.onInit
!insertmacro Init "uninstaller"
FunctionEnd
; eof

View File

@ -44,6 +44,14 @@ if (${env:OPENRCT2_ORG_TOKEN} -and -not $testing)
7z x nsisxtra.zip > $null
Check-ExitCode
cp FindProcDLL.dll "C:\ProgramData\chocolatey\lib\nsis.portable\tools\nsis-3.0b1\Plugins\x86-ansi"
Write-Host "Downloading UAC plugin for NSIS..." -ForegroundColor Cyan
curl "http://nsis.sourceforge.net/mediawiki/images/8/8f/UAC.zip" -OutFile uac.zip
Check-ExitCode
7z x uac.zip > $null
Check-ExitCode
cp UAC.nsh "C:\ProgramData\chocolatey\lib\nsis.portable\tools\nsis-3.0b1\Includes"
cp Plugins "C:\ProgramData\chocolatey\lib\nsis.portable\tools\nsis-3.0b1" -Recurse -Force
}
}
else