I use the code I find all over stackoverflow to run a runas
program in Python:
import subprocess as sp
prog = sp.Popen(
['runas', '/user:"[email protected]"', '/netonly', '"C:\foo\bar.bat"'], stdin=sp.PIPE
)
ww = "p@ssw0rd".encode("utf-8")
prog.stdin.write(ww)
prog.communicate()
Some remarks before the problem:
- it is not unsafe, in production I can safe the password in a Key Vault and retrieve it when used
- we cannot change the authorization method, we have to connect with some external AD for... reasons
In cmd, the C:\foo\bar.bat
asks for password and then works fine:
However, with subprocess I keep getting:
Enter the password for "[email protected]":
RUNAS ERROR: Unable to acquire user password
What am I doing wrong? I reckon it's a newline / return error or something?