I'm tryng to run a batch file in python with administrator privileges using runas
command.
My code is:
prog = subprocess.Popen(['runas', '/noprofile', '/user:Administrator', ' c:\windows\system32\addtask.bat'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,universal_newlines=True)
prog.stdin.write('mypass\n')
prog.stdin.flush()
output, error = prog.communicate()
if prog.returncode != 0:
print("FAILED: %d %s - %s" % (prog.returncode, output, error))
but it doesn't work. It outputs:
FAILED: 1 Enter the password for Administrator: - none
I think there's something wrong passing the password through stdin.
Any suggestions?