Last active
November 10, 2022 05:23
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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