Skip to content

Instantly share code, notes, and snippets.

@C0nw0nk
Last active November 10, 2022 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save C0nw0nk/0858f345ac9b30371cb526f64b7b68e5 to your computer and use it in GitHub Desktop.
Save C0nw0nk/0858f345ac9b30371cb526f64b7b68e5 to your computer and use it in GitHub Desktop.
Run batch command line script as admin automatically if user says no it will just ask again in a loop when the script ends or exits it will start again on loop
@echo off & setLocal EnableDelayedExpansion
TITLE ^start Admin elevation batch file and reboot script upon ^exit
:start
net session >nul 2>&1
if %errorlevel% == 0 (
goto :admin
) else (
@pushd %~dp0 & fltmc | find ^".^" && (powershell start '%~f0' ' %*' -verb runas 2>nul && exit /b)
)
goto :start
:admin
:start_loop
if "%~1"=="" (
start /wait /B %~dp0%~nx0 go 2^>Nul
) else (
goto begin
)
goto start_loop
:begin
pause
echo If you want to close this script just close the console window the exit loop keeps this script alive unless you close the window
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment