Force Batch File To Run As Admin [2021] Jun 2026

Give the code snippet above a try in your next script and let us know in the comments if it worked for you!

Always include this line at the top of your admin scripts to "reset" the path to the script's location: cd /d "%~dp0" force batch file to run as admin

@echo off net session >nul 2>&1 if %errorlevel% neq 0 ( echo Requesting administrator privileges... powershell start -verb runas '%0' exit /b ) Give the code snippet above a try in