Advertisement
gocha

BatchGotAdmin without altering echo (run as admin for batch)

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