run as administrator : Java Glossary


run as administrator

Oddly, in Windows, even when you are logged on as an administrator, your batch files (*.bat, *.btm, *.cmd) don’t have administrative privileges to do things such as correct the time, or update the C:\Windows\system32\drivers\etc\hosts. file. There are three ways around this.

  1. Use the task manager to schedule your batch files as future tasks with the run-as-administrator option.
  2. Instead of left clicking a batch file on the task bar to run it, right click it, then right click the name of the batch file again and select run as administrator. It will then ask Do you want to allow this app to make changes to your PC? as a last second check.
  3. Right click the shortcut then right click the name of the batch file again, then select properties, then select shortcut, then select advanced, then select run as administrator. Ever after the bat file will run as administrator, though you will still have to give the last second OK.

Unfortunately, according to the phases of the moon, Windows will not let you select the run-as-administrator option. I cannot see any pattern when it lets you and does not let you.


To detect whether your current script is running under administrative privilege type

net session >nul:
if errorlevel 1 goto noprivilege


Windows considers it necessary for whomever runs a bat file, not who composes it, to manually OK administrative privileges, even if they have not the first clue what they are. I can think of only one way around this.

You need hypothetical utility trigger.exe to run bat files as administrator without pestering the user for an OK. You schedule your bat file with the task manager to run some time in the distant future. You run a little utility you invoke with:

trigger.exe E:\env\mybat.bat

that reschedules mybat.bat 1 second into the future, lets the task manager launch it, then puts it back. Unfortunately, I know of no such little utility. Microsoft would probably be quite annoyed with me if I wrote one. It is more complicated than you would think. Trigger.exe itself must not require run as administrator. It must talk to a permanently running service that does the dirty work. It has to fiddle with Windows files without Windows panicking. From Windows point of view, it is malware.

If I were Microsoft, I would implement a legitimate simplified trigger.exe. There is no great danger in running a task now, but just in case, I would add a check box allow on demand to each task. Getting rid of those idiotic Do you want to allow this app to make changes to your PC? prompts would be a great selling point for a future OS (Operating System).

This page is posted
on the web at:

Optional Replicator mirror
on local hard disk J:

Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

Your face IP:[]
You are visitor number