This Stack Overflow question suggests a command which looks as if it should work, but it doesn't (that answer is deleted now, though):
Single line command for Run as a different user on Window 7 that contains a password also
The command would be:
echo PaSsWoRd | runas /user:Administrator cmd
However it says:
unknown user name or bad password.
The details are definitely correct though. For example, if I was to run:
runas /user:Administrator
...and on the next line, if I typed in PaSsWoRd
, it would work no problem.
To use runas at the command line, open a command prompt, type runas with the appropriate parameters, and then press ENTER. In the user interface for Windows Vista, the Run as… command has been changed to Run as administrator.
To close or exit the Windows command line window, also referred to as command or cmd mode or DOS mode, type exit and press Enter . The exit command can also be placed in a batch file.
The runas command does not allow a password on its command line. This is by design (and also the reason you cannot pipe a password to it as input).
The Runas command enables a user to perform tasks such as running a specific program with different permissions than what is currently available. Admins commonly use it to quickly perform administrative tasks while logged in to a non-admin account.
The runas command does not allow a password on its command line. This is by design (and also the reason you cannot pipe a password to it as input). Raymond Chen says it nicely:
The RunAs program demands that you type the password manually. Why doesn't it accept a password on the command line?
This was a conscious decision. If it were possible to pass the password on the command line, people would start embedding passwords into batch files and logon scripts, which is laughably insecure.
In other words, the feature is missing to remove the temptation to use the feature insecurely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With