Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- REM
- REM UAC-ME - For Batch Scripts (CMD or BAT) that need ELEVATION
- REM Add this code to the top of any batch script, and that's it!
- REM If admin rights arent't detected, It creates a vbscript file on-the-fly.
- REM It then launches that with a UAC request, which continues with your code.
- @echo off
- REM ===================================
- :: BEGIN UAC CHECK
- :: Check to see if we have admin privs. If not, elevate with prompt to user
- at > nul
- if '%errorlevel%' NEQ '1' (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"
- pause
- exit /B
- :gotAdmin
- if exist "%temp%\getadmin.vbs" (del "%temp%\getadmin.vbs")
- pushd "%CD%"
- CD /D "%~dp0"
- :: END UAC CHECK
- REM =====================================
- REM Your code goes below here.
- REM !Remember that echo is still off!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement