0

How do I write a bat file to run as administrator and then be able to have the credentials automatically entered in.

For example if it was user:LocalAdmin and password:password. I currently have the run as admin as

runas.exe /savecred /user:LocalAdmin "C:\Users\LocalAdmin\Desktop\test.bat"

But once I run this it asks me for a password. Is there a way to put the password in there so it does not ask for the password

2 Answers 2

0

In looking at the help for /SAVECRED it may be possible to run it once with manually entering the credentials, and then the next run will used the saved credentials.

If that doesn't work, look at a way to use Impersonation from a scripting language (VBScript or PowerShell for example).

0

If you are asking if you can bypass the UAC prompt, the answer is no. See the following blog post for the reasons:

FAQ: Why can't I bypass the UAC prompt?

Relevant excerpts from that FAQ:

The designers of Windows Vista's User Account Control expressly decided not to incorporate functionality like setuid/suid or sudo found in Unix and Unix-like OSes such as Mac OS X. I think they made the right decision.

...

If it were possible to mark an application to run with silently-elevated privileges, what would become of all those apps out there with LUA bugs? Answer: they'd all be marked to silently elevate. How would future software for Windows be written? Answer: To silently elevate. Nobody would actually fix their apps, and end-user applications will continue to require and run with full administrative permissions unnecessarily.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.