Let me start by admitting I have zero knowledge on how to interact with windows security/account services.
TL;DR: Have an .exe always run as a specified (non-admin) user on windows, no matter what user initializes it, without being prompted for login.
I have a python script that accesses files stored in a secured folder on the network. The script works perfectly for any user who has been granted access to said folder. I want to be able to allow all users on the network to run the .exe without granting the users access to the folder. To get around this, a user has been created whose only function is to have access to this folder. The goal is to have the .exe always run as that "special" user without a login prompt.
I have tried the following Run program as different user on Windows (not admin) within a Python script by copying and pasting the code provided as the answer. (It errors out on line 40 (1722, 'LookupAccountName', 'The RPC server is unavailable.') I can't find a good article to explain how to trouble shoot that error. I have also tried Request UAC elevation from within a Python script?, but I don't understand the syntax to have it run as a specific user. (if possible)
I have also tested doing something like the below. If I type the runas arguments directly into the command prompt it does run the notepad.exe as that user. (provided I input the password). I can't seem to get the python .exe to key the arguments into the command prompt on it's own. (notepad was used just to test that the user account was working properly and not the issue)
import os os.system("start /wait cmd runas /user:(domain)\(user) ""C:\\Windows\\system32\\notepad.exe""")
I have even tried to find some C++ code that I can use to have it run the python .exe, since I assume C++ is better for this task. I can't seem to find any opensource code for this however, and having zero C++ knowledge can't even begin to make something myself. Or, maybe I am going about this all wrong and there is a better method for this I could be directed to. Any guidance would be appreciated.