erictbar

Run Batch Script as Admin

Feb 14th, 2023 (edited)
182
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | Source Code | 0 0
  1. @echo off
  2.  
  3. call :isAdmin
  4.  
  5. if %errorlevel% == 0 (
  6. goto :run
  7. ) else (
  8. echo Requesting administrative privileges...
  9. goto :UACPrompt
  10. )
  11.  
  12. exit /b
  13.  
  14. :isAdmin
  15. fsutil dirty query %systemdrive% >nul
  16. exit /b
  17.  
  18. :run
  19. ## your command here
  20. powershell -command "get-process *steam* | stop-process
  21. exit /b
  22.  
  23. :UACPrompt
  24. echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
  25. echo UAC.ShellExecute "cmd.exe", "/c %~s0 %~1", "", "runas", 1 >> "%temp%\getadmin.vbs"
  26.  
  27. "%temp%\getadmin.vbs"
  28. del "%temp%\getadmin.vbs"
  29. exit /B`
  30.  
  31.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment