@echo off :: This is for handling automatic check for and requesting :: elevation (if needed): set got_elevated= if "%~1" == "got_elevated" set got_elevated=1 if "%~1" == "got_elevated" shift set is_elevated= net session >nul 2>&1 if "%errorlevel%" == "0" set is_elevated=1 if not defined is_elevated powershell start-process -verb runas cmd.exe -argumentlist '/k %cd%\%~nx0 got_elevated' if not defined is_elevated exit /b :: This is the core logic, fetching the session ID at runtime :: and then using tscon to disconnect from it and "send" it :: back to the computer's physical/logical "console", to :: avoid that the display is unusual and blocking automation: powershell "exit [System.Diagnostics.Process]::GetCurrentProcess().SessionId" tscon %errorlevel% /dest:console :: This is for handling automatic check for and requesting :: elevation (if needed): if defined got_elevated exit