I want to run an application in user mode from admin account using python. I tried runas command in subprocess. It is asking for the password. I want to give the password automatically. How can I do that ?
Asked
Active
Viewed 199 times
-1
-
Can you show us your code ? what you tried sofar, where it goes wrong ... etc... – Edwin van Mierlo Nov 28 '17 at 08:01
-
@EdwinvanMierlo I have tried something like this "subprocess.Popen('runas /user:user2
')" This is asking for password. With "/savecred " also I have tried and it asks for the password once. So I can't use this also. – Sreevalsa E Nov 29 '17 at 04:39 -
Similar question has already been answered , with method to pass password programtically https://stackoverflow.com/questions/47380378/run-process-as-admin-with-subprocess-run-in-python/47385474#47385474 – pankaj mishra Nov 29 '17 at 13:11
1 Answers
0
With runas
you do not have the option to give a password for the runas /user
, and with /savecred
it will still need the password at least once.
I would like to suggest that you do this through task scheduler, which has a command line interface schtasks
Various parameters you can use to specify user and runas user:
schtasks /Create /?
gives you the help for this feature
You probably want to pay attention to:
/RU
runas user
/RP
runas password
Now, you probably don't get any stdout from this process, so ensure you redirect to file which you can read when the process finishes.

Edwin van Mierlo
- 2,398
- 1
- 10
- 19