Advertisement
FocusedWolf

Batch: UAC Prompt

Jul 17th, 2019
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.58 KB | None | 0 0
  1. I just put the finishing touches on this.
  2. I think it might be the shortest way to do it.
  3.  
  4. This solution depends on PowerShell existing on the computer.
  5.  
  6. The basic flow is cmd.exe is started to start powershell.exe (this has the effect of hiding the powershell's blue window), and finally powershell executes the command to run the current script with admin privileges.
  7.  
  8. Any argument you supply to the script will also be forwarded to the restarted script.
  9.  
  10. If you found this useful then allow me to also share with you my donation link:
  11. https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=3HVWGXQ9U9F5W&currency_code=USD&source=url
  12.  
  13.     @echo off
  14.  
  15.     :CheckPermissions
  16.         fltmc >nul 2>&1 || (
  17.             echo Requesting administrative privileges...
  18.             start cmd /c powershell.exe -Command "Start-Process cmd -Verb runas -ArgumentList '/c \"\"%~s0\"\" %*'"
  19.             exit /B
  20.         )
  21.  
  22.     :Work
  23.         echo Do some admin things here.
  24.         pause
  25.  
  26. Here's a longer version for testing purposes:
  27.  
  28.     @echo off
  29.  
  30.     :CheckPermissions
  31.         fltmc >nul 2>&1 || (
  32.             echo Requesting administrative privileges...
  33.             start cmd /c powershell.exe -Command "Start-Process cmd -Verb runas -ArgumentList '/c \"\"%~s0\"\" %*'"
  34.             exit /B
  35.         )
  36.  
  37.     :Test
  38.         echo Script Path: "%~s0"
  39.         echo Script Parameters (blank if you don't supply any): %*
  40.         echo.
  41.  
  42.         fltmc >nul 2>&1 && (
  43.             echo Admin powers activated!
  44.         ) || (
  45.             echo Need Admin!
  46.         )
  47.         echo.
  48.         pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement