Posted By

deanhouseholder on 03/12/14


Tagged

command administrator batch dos prompt admin cmd vbs uac


Versions (?)

Batch script to open an Administrator CMD shell


 / Published in: PHP
 

This batch script writes a temporary .vbs file which will invoke a UAC prompt to open an administrator command prompt. This makes it easy to create a shortcut to an admin prompt.

  1. :::::::::::::::::::::::::::::::::::::::::
  2. :: Automatically check & get admin rights
  3. :::::::::::::::::::::::::::::::::::::::::
  4. @echo off
  5. CLS
  6. ECHO =============================
  7. ECHO Running Admin shell
  8. ECHO =============================
  9.  
  10. :checkPrivileges
  11. NET FILE 1>NUL 2>NUL
  12. if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
  13.  
  14. :getPrivileges
  15. if '%1'=='ELEV' (shift & goto gotPrivileges)
  16. ECHO **************************************
  17. ECHO Invoking UAC for Privilege Escalation
  18. ECHO **************************************
  19.  
  20. setlocal DisableDelayedExpansion
  21. set "batchPath=%~0"
  22. setlocal EnableDelayedExpansion
  23. ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
  24. ECHO UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
  25. "%temp%\OEgetPrivileges.vbs"
  26. exit /B
  27.  
  28. :gotPrivileges
  29. ::::::::::::::::::::::::::::
  30. :START
  31. ::::::::::::::::::::::::::::
  32. setlocal & pushd .
  33.  
  34. REM Run shell as admin (example) - put here code as you like
  35. cmd /k echo. && echo *** ADMIN CONSOLE ***

Report this snippet  

You need to login to post a comment.