Script to open cmd as a domain administrator

batoli1234
batoli1234 used Ask the Experts™
on
Hello,
is this posible?
I need a simple script, to open up a command prompt as a domain administrator. Preferably without being prompted for the password. The password should be coded in to the script.

Thanks,
Bat.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
JohnBusiness Consultant (Owner)
Most Valuable Expert 2012
Expert of the Year 2018
Commented:
It will need to prompt for credentials, otherwise your server is hopelessly insecure
End-user support
Commented:
You can use the RUNAS with the /savecred option.

While logged on as domain admin, create a new shortcut to CMD. Put in the following command:
runas /user:hostname\Administrator /savecred “C:\Windows\System32\cmd.exe”

The first time you double-click your shortcut, you’ll be prompted to enter the domain admin's password.

See example here: https://www.howtogeek.com/124087/how-to-create-a-shortcut-that-lets-a-standard-user-run-an-application-as-administrator/
JohnBusiness Consultant (Owner)
Most Valuable Expert 2012
Expert of the Year 2018

Commented:
I would be concerned that anyone who might find the script would be in like flint. I like better security than this, but then you may have a different view.
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

NVITEnd-user support

Commented:
Correction to my prior post:
While logged on as domain admin, create a new shortcut to CMD
...should be:
While logged on as the user, create a new shortcut to CMD

The password is not saved in the shortcut itself. It is saved in the user's vault accessed via Credential Manager.
The asker should be aware of this.
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018
Commented:
Use
runas /netonly /user:Domain\Administrator /password:* cmd.exe

Open in new window


Do not use savecred because credential can be used to start other processes elevated
Vikas BhatExperienced IT Infrastructure Services/operations Manager
Commented:
Please check my article https://techofmeblogs.wordpress.com/2017/03/07/vb-scripts-and-uac-elevation/

I have also provided a script that can be of help.
JohnBusiness Consultant (Owner)
Most Valuable Expert 2012
Expert of the Year 2018

Commented:
Proper answers and advice provided

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