How to code a BAT file to always run as admin mode?
You use runas
to launch a program as a specific user:
runas /user:Administrator Example1Server.exe
The other answer requires that you enter the Administrator account password. Also, running under an account in the Administrator Group is not the same as run as administrator see: UAC on Wikipedia
Windows 7 Instructions
In order to run as an Administrator, create a shortcut for the batch file.
- Right click the batch file and click copy
- Navigate to where you want the shortcut
- Right click the background of the directory
- Select Paste Shortcut
Then you can set the shortcut to run as administrator:
- Right click the shortcut
- Choose Properties
- In the Shortcut tab, click Advanced
- Select the checkbox "Run as administrator"
- Click OK, OK
Now when you double click the shortcut it will prompt you for UAC confirmation and then Run as administrator (which as I said above is different than running under an account in the Administrator Group)
Check the screenshot below
Note: When you do so to Run As Administrator, the current directory (path) will not be same as the bat file. This can cause some problems in many cases that the bat file refer to relative files beside it. For example, in my Windows 7 the cur dir will be SYSTEM32 instead of bat file location! To workaround it, you should use
cd "%~dp0"
or better
pushd "%~dp0"
to ensure cur dir is at the same path where the bat file is.