I have a batch file that requests UAC privileges. When the UAC box pops up and a user clicks the
no button I want to display message
No administration privileges granted. Now exiting. and then wait three seconds before exiting. Currently If a user clicks the
yes button the UAC prompt works, but in the background on a separate window with the exit message I applied above.
I have tried to create an IF statement towards the end of the file to specify which exit takes place dependent on the yes/no press.
Essentially I want to do a quick exit of the other command prompt window if a user clicks
yes or display the exit message for the three seconds before exiting. Any ideas?
IF '%params%' EQU == 1 ( ECHO No administration privileges granted. Now exiting. TIMEOUT 3 >NUL EXIT /B ) ELSE ( EXIT )
@ECHO OFF REM Check for permissions >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" REM Check if UAC has been granted IF '%errorlevel%' EQU '0' ( GOTO Administration_Granted ) ELSE ( GOTO UAC_Prompt ) REM Request administration privileges :UAC_Prompt ECHO Requesting administration privileges. ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" SET params = %*:"="" ECHO UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" DEL "%temp%\getadmin.vbs" CLS IF "%params%"=="1" ( ECHO No administration privileges granted. Now exiting. TIMEOUT 3 >NUL EXIT /B ) ELSE ( EXIT ) REM Administration Granted :Administration_Granted ECHO Administration privileges have been granted TIMEOUT 2 >NUL PAUSE