Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch Script to Run as Administrator

Tags:

I'm writing a client/server checking program but it needs to run as Administrator.

I want this to run silently on my network and users, and I don't want the "Run as" Administrator" prompt. Is there any beginning code that I can place into the batch file to make it auto-run as Administrator?

like image 775
Frustrated Python Coder Avatar asked Feb 01 '13 04:02

Frustrated Python Coder


People also ask

How do I run as administrator in cmd?

You can also open a command prompt using a run-box (Windows + R). To do so, open a run-box, write cmd , and press Control + Shift + Enter to open the command prompt as an administrator. Ace your System Design Interview and take your career to the next level.


1 Answers

Solutions that did not work

No: The - create a shortcut [ -> Compatibility -> "run this program as an administrator" ] solution does not work.

This option is greyed out in Windows 7. Even with UAC disabled

No: The runas /env /user:domain\Administrator <program.exe/command you want to execute> is also not sufficient because it will prompt the user for the admin password.

Solution that worked

Yes: Disable UAC -> Create a job using task scheduler, this worked for me.

  • Create a job under task scheduler and make it run as a user with administrator permissions.
  • Explicitly mark: "Run with highest privileges"
  • Disable UAC so there will be no prompt to run this task

You can let the script enable UAC afterwards by editing the registry if you would want. In my case this script is ran only once by creation of a windows virtual machine, where UAC is disabled in the image.

Still looking forward for the best approach for a script run as admin without too much hassle.

like image 148
zenin Avatar answered Sep 28 '22 10:09

zenin