From d84db2d4636413fe77818516931aa0155f9d2a50 Mon Sep 17 00:00:00 2001 From: Richard Jenkins Date: Sun, 13 Aug 2017 01:37:40 +0100 Subject: [PATCH] Fix #6169: Windows installer runs game with admin privileges (#6171) --- distribution/windows/install.nsi | 40 ++++++++++++++++++++++++++++++-- scripts/ps/appveyor_install.ps1 | 8 +++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/distribution/windows/install.nsi b/distribution/windows/install.nsi index 73d2b9cf76..5ecb78260c 100644 --- a/distribution/windows/install.nsi +++ b/distribution/windows/install.nsi @@ -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 diff --git a/scripts/ps/appveyor_install.ps1 b/scripts/ps/appveyor_install.ps1 index 39de1eacaf..898b098d8b 100644 --- a/scripts/ps/appveyor_install.ps1 +++ b/scripts/ps/appveyor_install.ps1 @@ -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