Python: how to start a process with administrator permission?

I am running the following script from the Windows 7 command prompt with administrator privileges:

import win32com.client import time import SendKeys import os from ctypes import * shell = win32com.client.Dispatch("WScript.Shell") os.startfile("C:\...exe") 

I also assigned the function "Run this program as administrator" to python.exe under "Properties"> "Compatibility"> "Privilege Level". It didn’t change anything.

The program still behaves differently when it opens in the way it behaves, when I simply open it with a double click on the screen. Did I miss some important bit here? Will the called process start in this way, as if it were started with administrator privileges?

Thanks for your help in advance!

Greetings -

Pat

+4
source share
2 answers

I do not have access to Vista or Windows 7, but you can use the runas command.

 import subprocess subprocess.call(['runas', '/user:Administrator', 'C:/my_program.exe']) 
+2
source

OK ... I understand what the problem is. This actually had nothing to do with permissions, contrary to my initial suspicion. Sorry for that!

The reason the application was not working correctly was because the Python script was located and called in another directory. For this reason, some of the application dependencies were not correctly specified and could not find some files that need to be run properly. Moving a python script to the same directory as the called application was one way to fix this.

Sorry again for the misleading initial interpretation of what seemed to be a question.

0
source

Source: https://habr.com/ru/post/1334908/


All Articles