Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- title UAC example for batch files
- REM Check for permissions
- >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
- REM If the error flag set, we do not have admin permissions.
- if '%errorlevel%' NEQ '0' (
- echo Requesting administrative privileges...
- goto UACPrompt
- ) else (goto GotAdmin)
- REM Ask for admin permissions.
- :UACPrompt
- 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"
- exit /B
- REM Execute once admin permissions are granted.
- :GotAdmin
- REM DO STUFF HERE
Advertisement