Merge pull request #4 from neoOpus/patch-1

Add check UAC script
This commit is contained in:
Martin Eesmaa
2022-04-28 09:39:28 +00:00
committed by GitHub

View File

@ -2,21 +2,39 @@ echo off
pushd "%~dp0" pushd "%~dp0"
cls cls
echo. REM === check and get the UAC for administrator privilege ===
echo :: Checking For Administrator Elevation... REM === code from https://sites.google.com/site/eneerge/scripts/batchgotadmin
echo. :: BatchGotAdmin
timeout /t 1 /nobreak > NUL :-------------------------------------
openfiles > NUL 2>&1 REM --> Check for permissions
if %errorlevel%==0 ( >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
echo Elevation found! Proceeding...
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
if '%1' EQU '1' (
echo Cannot elevate administrator privilege
echo Please try again with "Run as Administrator"
echo Installation failed.
pause
exit /B
) else ( ) else (
echo :: You are NOT running as Administrator echo Requesting administrative privileges...
echo. goto UACPrompt
echo Right-click and select ^'Run as Administrator^' and try again.
echo Press any key to exit...
pause > NUL
exit
) )
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "1", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
:--------------------------------------
goto welcomenow goto welcomenow