Force Batch File To Run As Admin

To run it manually later, you can create a shortcut with this command: schtasks /run /tn "YourTaskName" Method 4: The PowerShell Wrapper

If you don't want to mess with the code inside the file, you can use a Windows Shortcut.

The screen flickered. A UAC box popped up: "Do you want to allow this app to make changes?"

When a Batch file runs as an administrator, Windows often changes the working directory to C:\Windows\System32 . This can break your script if it relies on files located in the same folder as the script itself.

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

force batch file to run as admin

Присоединиться

Сообщить об опечатке

Текст, который будет отправлен нашим редакторам: