Python: Running just parts of an automation script in elevated mode

126 views Asked by At

I'm running some automation tests, and some parts have to be run in elevated mode to work. Which is fine; I'm using shell.ShellExecuteEx from the pywin32 library to call my own scripts, and that works just fine.

These are the exact parameters I am using:

shell.ShellExecuteEx(
                     nShow=win32con.SW_SHOWNORMAL,
                     fMask=win32com.shell.shellcon.SEE_MASK_NOCLOSEPROCESS,
                     lpVerb='runas', 
                     lpFile='<path to executable>',
                     lpParameters='<parameter string>'
                     )

My method thus far has been to put my entire automation code into one module, and then call that module with elevated privileges.

However, some of my code can only work if it is not running in elevated mode. I have to switch between the two. How can I achieve this?

0

There are 0 answers