Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I just put the finishing touches on this.
- I think it might be the shortest way to do it.
- This solution depends on PowerShell existing on the computer.
- 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.
- Any argument you supply to the script will also be forwarded to the restarted script.
- If you found this useful then allow me to also share with you my donation link:
- https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=3HVWGXQ9U9F5W¤cy_code=USD&source=url
- @echo off
- :CheckPermissions
- fltmc >nul 2>&1 || (
- echo Requesting administrative privileges...
- start cmd /c powershell.exe -Command "Start-Process cmd -Verb runas -ArgumentList '/c \"\"%~s0\"\" %*'"
- exit /B
- )
- :Work
- echo Do some admin things here.
- pause
- Here's a longer version for testing purposes:
- @echo off
- :CheckPermissions
- fltmc >nul 2>&1 || (
- echo Requesting administrative privileges...
- start cmd /c powershell.exe -Command "Start-Process cmd -Verb runas -ArgumentList '/c \"\"%~s0\"\" %*'"
- exit /B
- )
- :Test
- echo Script Path: "%~s0"
- echo Script Parameters (blank if you don't supply any): %*
- echo.
- fltmc >nul 2>&1 && (
- echo Admin powers activated!
- ) || (
- echo Need Admin!
- )
- echo.
- pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement