Zachary Ott
Zachary Ott

Reputation: 33

Python script to launch a program as a different user

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.

Upvotes: 1

Views: 2741

Answers (1)

Petr L.
Petr L.

Reputation: 480

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

Upvotes: 0

Related Questions