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.


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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.