question

HaoSun-0098 avatar image
0 Votes"
HaoSun-0098 asked Jason-MSFT commented

How to give python admin priviledges or call python with admin priviledges?

What would be the equivalent of python3.8 setup.py install but having python run with admin privileges? p.s. can I give python admin privileges without having to reinstall to a different location?

windows-10-security
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Jason-MSFT avatar image
0 Votes"
Jason-MSFT answered FanFan-MSFT converted comment to answer

Sorry, it's unclear what exactly you are asking about here. In Windows, you give users or groups (security principals) privileges and permissions (and not applications). So, what exactly are you trying to do or what exactly is not working that you would like to address?

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If I run cmd as administrator and call python 3.8 setup.py python runs without admin privileges and cannot do the setup properly. I would like to change that.

0 Votes 0 ·

How do you know this is the issue?

All child processes inherit the token and thus privileges of the process that launched them which are based on the user that launched them.

Ultimately, this has nothing to do with Intune though, so I'm removing the Intune tag and adding a Windows 10 tag.

0 Votes 0 ·
HaoSun-0098 avatar image
0 Votes"
HaoSun-0098 answered Jason-MSFT commented

I reran using subprocess.call(['python.exe', 'setup.py', 'install']) following https://stackoverflow.com/questions/19672352/how-to-run-python-script-with-elevated-privilege-on-windows rather than python setup.py install and things worked

· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,
 
I am glad to hear that your issue was successfully resolved.
You can accept your solution as answer to help more people who encounters similar issues..
If there is anything else we can do for you, please feel free to post here.
 
Best Regards,

0 Votes 0 ·

The thing is I would like python to be able to inherit admin privileges by default rather than this somewhat adhoc solution.

0 Votes 0 ·

As noted, that still doesn't make sense. That's not how permissions and privileges work. Processes run in a user-context and thus gain the permissions and privileges of the user that launched them. You cannot individually assign them to a process or application.

Based on the StackOverflow you linked to, your actual request here is to launch a child process (or script) using Python in an elevated context. That requires you to add code to your Python script to elevate the privileges of the user, assuming they are local admins already or to launch the Python interpreter elevated in the first place.

0 Votes 0 ·
Show more comments