Update VVCEasy.bat

check and get the UAC for administrator privilege
This commit is contained in:
Anoir Ben Tanfous 2022-04-24 00:06:56 -04:00 committed by GitHub
parent db9995454a
commit 3a2bd88916
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 15 deletions

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...
) else ( REM --> If error flag set, we do not have admin.
echo :: You are NOT running as Administrator if '%errorlevel%' NEQ '0' (
echo. if '%1' EQU '1' (
echo Right-click and select ^'Run as Administrator^' and try again. echo Cannot elevate administrator privilege
echo Press any key to exit... echo Please try again with "Run as Administrator"
pause > NUL echo Installation failed.
exit pause
) exit /B
) else (
echo Requesting administrative privileges...
goto UACPrompt
)
) 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