Advertisement
Combreal

ruAsAdmin.bat

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