Unable to supply password to runas from commandline

elevated-privilegespasswordsrunas

I am unable to supply password to runas from commandline

I have tried the following

cmd /C echo my_admin_password | runas /user:DOMAIN\my_admin_login c:\test.bat

and

echo my_admin_password | runas /user:DOMAIN\my_admin_login c:\test.bat

And the error I get is

Attempting to start c:\test.bat as user "DOMAIN\my_admin_login" …
RUNAS ERROR: Unable to run – c:\test.bat
1326: Logon failure: unknown user name or bad password.

How do I fix this?

Best Answer

Take a look at this link: runas utility

It's a runas free utility that have the follwing features:

  1. It accepts password as a command line parameter so that it can be used in batch files.

  2. It can bind started process to the interactive user Desktop so it can be used to start interactive processes from various services such as 24x7 Scheduler, 24x7 Event Server and other.

  3. Note: Professional version of RunAs also supports encryption of the entire command line, which administrators can use to give regular users access to certain programs requiring admin-level privileges. Users don't need to know the administrator's password and cannot use it to run anything elseā€¦ simple, yet very efficient solution for this common problem.

Also you can try pass the password as input for the process using subprocess.Popen.communicate or even subprocess.Popen.stdin.write.

Other interesting links:

How to pass a password to a process?

Command-line runas with password

PsExec

Related Topic