Skip to content

Instantly share code, notes, and snippets.

@thushan
Created July 2, 2018 07:38
Show Gist options
  • Save thushan/96c98f861a16b98626ed64f5e5966de2 to your computer and use it in GitHub Desktop.
Save thushan/96c98f861a16b98626ed64f5e5966de2 to your computer and use it in GitHub Desktop.
Auto-Elevate Batch Script
REM Credit: https://stackoverflow.com/a/25756858
REM Save current directory which lets us come back to our working directory
pushd %~dp0
net file 1>nul 2>nul && goto :run || powershell -ex unrestricted -Command "Start-Process -Verb RunAs -FilePath '%comspec%' -ArgumentList '/c %~fnx0 %*'"
goto :eof
:run
REM Run any elevated tasks here
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment