1

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.

2
  • You have no code example. SO is not a code writing service Commented 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. Commented Aug 6, 2021 at 13:44

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much. Never would have found this!
not work, os.system and subprocess.Popen is in different thread.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.