How to Complete the Runas Command in One Line [Closed]

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.

3

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.

20
Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest