BloodyFoxy

BatchGotAdmin

Oct 4th, 2013
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2.  
  3. :: BatchGotAdmin
  4. :-------------------------------------
  5. REM  --> Check for permissions
  6. >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
  7.  
  8. REM --> If error flag set, we do not have admin.
  9. if '%errorlevel%' NEQ '0' (
  10.     echo Requesting administrative privileges...
  11.     goto UACPrompt
  12. ) else ( goto gotAdmin )
  13.  
  14. :UACPrompt
  15.     echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
  16.     echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
  17.  
  18.     "%temp%\getadmin.vbs"
  19.     exit /B
  20.  
  21. :gotAdmin
  22.     if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
  23.     pushd "%CD%"
  24.     CD /D "%~dp0"
  25. :--------------------------------------
  26. cd %SYSTEMROOT%\system32
  27. cmd.exe /k
Advertisement
Add Comment
Please, Sign In to add comment