How call windows batch script using ADMINISTRATOR's CMD console

mac_g
mac_g used Ask the Experts™
on
I have few OS commands which I need to run only through ADMINISTRATOR's CMD console
please advice how to call such batch script

example :TEST.BAT
how to make sure below  script called from admin cmd console
==

echo " Hello"

==
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
C:\>runas /user:<localmachinename>\administrator test.bat
or
runas.exe /user:administrator "full path to batch file"
JohnBusiness Consultant (Owner)
Most Valuable Expert 2012
Expert of the Year 2018

Commented:
You would likely then be challenged for Admin Credentials (normal).  

If you want to run the script regularly and can do so at a predetermined time (schedule), you can run it from Task Scheduler with elevated admin credentials.
mac_gAdmin - Middleware Servers

Author

Commented:
I ran sample script using below command ... It is asking for password.

I am getting pause screen with--- " Enter the password for administrator:"
please advice

===================


runas.exe /user:administrator E:\temp\test.bat
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

JohnBusiness Consultant (Owner)
Most Valuable Expert 2012
Expert of the Year 2018

Commented:
That is what I noted above that you need admin credentials to run the script.

Do you have the admin password?
mac_gAdmin - Middleware Servers

Author

Commented:
there are 2-3 admin users  in servers ... which user, & how to provide password when we plan to run script as batch script offline ?
JohnBusiness Consultant (Owner)
Most Valuable Expert 2012
Expert of the Year 2018

Commented:
Each Admin could have the batch file (copy thereof) and run it with their credentials
The suggestion to use TaskScheduler is the normal way, but if you need this on-demand, use a PowerShell Script and get a toy from:

https://blogs.technet.microsoft.com/elevationpowertoys/

To run an elevated command window in the script.  I've been using this for a while, but I didn't originate it -- found in a StackOverflow thread on this very subject.  use the search: "powershell script run bat file with admin credentials"

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial