Advertisement
shornby

UAC-ME! For Batch Scripts (CMD or BAT) needing ELEVATION.CMD

May 15th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 0.98 KB | None | 0 0
  1. REM
  2. REM UAC-ME - For Batch Scripts (CMD or BAT) that need ELEVATION
  3. REM          Add this code to the top of any batch script, and that's it!
  4. REM          If admin rights arent't detected, It creates a vbscript file on-the-fly.
  5. REM          It then launches that with a UAC request, which continues with your code.
  6. @echo off
  7. REM ===================================
  8. :: BEGIN UAC CHECK
  9. :: Check to see if we have admin privs.  If not, elevate with prompt to user
  10. at > nul
  11. if '%errorlevel%' NEQ '1' (goto UACPrompt) else (goto gotAdmin)
  12. :UACPrompt
  13.     echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
  14.     echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
  15.     "%temp%\getadmin.vbs"
  16. pause
  17.     exit /B
  18. :gotAdmin
  19.     if exist "%temp%\getadmin.vbs" (del "%temp%\getadmin.vbs")
  20.     pushd "%CD%"
  21.     CD /D "%~dp0"
  22. :: END UAC CHECK
  23. REM =====================================
  24. REM Your code goes below here.
  25. REM !Remember that echo is still off!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement