I'm looking to make a python script that will launch a specified exe file in Windows under another user's context. Effectively, automating the "run as another user". I have a program that only works on the user the program is installed on, or an admin. We have several workstations that need to have multiple users run this program, but I'm not given them admin rights. I have a service account with limited privileges that will be used as the user. I need the script to pass the username and password, so the user does not need to enter it. A big plus if it can run silently so no dialog box shows when the script runs.
-
You have no code example. SO is not a code writing servicePetr L.– Petr L.2021-08-06 13:31:45 +00:00Commented Aug 6, 2021 at 13:31
-
I've tried looking for documentation on what commands I would need and keep getting guides on how to run a script as a different user, not how to run a program as a different user with a script. If you know a resource that can point me in the right direction, I would appreciate it! Thanks.Zachary Ott– Zachary Ott2021-08-06 13:44:29 +00:00Commented Aug 6, 2021 at 13:44
Add a comment
|
1 Answer
This is how to open programs with Python
import os
import subprocess
os.system("runas /user:cpandl\cgreen")
subprocess.Popen([r"U:\notme\program.exe"])
For more info on how to run with alternate credentials visit https://social.technet.microsoft.com/wiki/contents/articles/1410.windows-how-to-run-with-alternate-credentials-and-open-elevated-command-prompts.aspx
2 Comments
Zachary Ott
Thank you so much. Never would have found this!
傅继晗
not work, os.system and subprocess.Popen is in different thread.