You should receive an "ERROR: Access is denied." unless you are running Elevated. This error is output to STDERR, which is how we can catch it in the syntax I used.
Worlds coolest batch admin check Betcha everybody puts this in their batch's I have put your code demonstration in first post of batch repository Feel free to teach any level of batch coding and I'll put in that first post Thanks
I found this snippet a while back in a script that allows concurrent remote desktop sessions and changed it a bit. Code: SET HasAdminRights=0 FOR /F %%i IN ('WHOAMI /PRIV /NH') DO ( IF "%%i"=="SeTakeOwnershipPrivilege" SET HasAdminRights=1 ) IF NOT %HasAdminRights%==1 ( "%~dp0Error.vbs" EXIT ) Error.vbs Code: MsgBox "This script must be run with Administrator privileges!", 16, "Error!"
batch file auto admin uac prompt found this script to give automatic elevated admin privilege Code: @Echo off :: Check for permissions >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" :: If error flag set, we do not have admin. if '%errorlevel%' NEQ '0' ( Echo Requesting administrative privileges... goto UACPrompt ) else ( goto gotAdmin ) :UACPrompt Echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" Echo UAC.ShellExecute "%~s0", "", "", "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" REM <YOUR BATCH SCRIPT HERE> ECHO. ECHO You should have had a UAC Prompt ECHO and now you have Admin Rights ECHO. pause copy that code to a txt file and name it testadmin.cmd and run it got it from here, http://ss64.com/nt/runas.html