1
import subprocess
import sys

password_d=raw_input("Input password")
prog = subprocess.Popen(['runas', '/user:KP\svc','cmd.exe'],universal_newlines=True,stdin=subprocess.PIPE,stdout=sys.stdout)
prog.stdin.write(password_d)
prog.communicate()[0]

This is my code. I am trying to login as another user through runas.exe and provide the password through already stored input object password_d which is taken from the user.

When i try to do this it says the password is incorrect. How can i achieve this in python and how can i print what is being fed as input. any leads would really be helpful.

Yuval.R
  • 1,182
  • 4
  • 15
  • Look into pexpect: https://pexpect.readthedocs.io/en/stable/ – Hielke Walinga Dec 21 '20 at 09:23
  • Are you sure you provide the correct password? According to the answer you seem to be on the right track: https://stackoverflow.com/questions/47380378/run-process-as-admin-with-subprocess-run-in-python – jpihl Dec 21 '20 at 09:32
  • I am using the right password.@jpihl.How can i print what is being fed into stdin? – Karthik Prabhu Dec 21 '20 at 09:50
  • First, you can print what is being fed into stdin with a `print` statement. Second, if the program is expecting input from stdin, normally that input would be terminated with a '\r\n' sequence, which is missing in your code since `input` does not include that. Try appending that to `password_d` to see if it makes a difference. – Booboo Dec 21 '20 at 11:20

0 Answers0