Request admin (UAC) access from Windows batch (.bat) file

Put the following code snippet into the top of your bat file. PowerShell is required.

"%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
IF %ERRORLEVEL% NEQ 0 (
  powershell -Command "Start-Process -Verb RunAs -FilePath '%0' -ArgumentList '%*'"
  exit /b
)

Leave a Reply

Your email address will not be published. Required fields are marked *