[python-win32] Dispatching something that requires elevation
Vernon D. Cole
vernondcole at gmail.com
Sat Jun 9 12:52:12 EDT 2018
look in github.com/salt-bevy/sudo.py
<https://github.com/salt-bevy/salt-bevy/blob/master/configure_machine/sudo.py>
for a module which will request elevated privileges for a Python script
running as a normal user.
Perhaps that can help create a solution for your use case.
There is a sample call for it in bootstrap_bevy_member_here.py or you can
just run it from the command line with the script you want to run as
administrator as its arguments.
On Fri, Jun 8, 2018 at 11:11 PM, Simon McConnell <simonmcconnell at gmail.com>
wrote:
> Hi,
>
> I am trying to dispatch a COM interface of a program that is set to "Run
> as Administrator" in the Compatibility Settings of its properties. Running
> the script w/o elevation results in a 'requires elevation' error. Running
> the script with elevation results in a 'server execution failed' error,
> which I understand to be "I can't find that thing". Removing the "Run as
> Administrator" from the Compatibility settings and running the script w/o
> elevation works, but unfortunately, this program needs to be run as
> administrator. When opening the program manually I have to accept the UAC
> popup and cannot turn it off thanks to Group Policy. Any clues?
>
> import win32com.client
> o = win32com.client.Dispatch("CimplicityME.Application")
>
>
> gives the error:
>
>
> Traceback (most recent call last):
> File "C:\Users\smcconnell\PycharmProjects\proficy\venv\
> lib\site-packages\win32com\client\dynamic.py", line 89, in
> _GetGoodDispatch
> IDispatch = pythoncom.connect(IDispatch)
> pywintypes.com_error: (-2147221021, 'Operation unavailable', None, None)
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
> File "C:\Users\smcconnell\PycharmProjects\proficy\src\proficy.py", line
> 5, in <module>
> o = win32com.client.Dispatch("CimplicityME.Application")
> File "C:\Users\smcconnell\PycharmProjects\proficy\venv\
> lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
> dispatch, userName = dynamic._GetGoodDispatchAndUserName(
> dispatch,userName,clsctx)
> File "C:\Users\smcconnell\PycharmProjects\proficy\venv\
> lib\site-packages\win32com\client\dynamic.py", line 114, in
> _GetGoodDispatchAndUserName
> return (_GetGoodDispatch(IDispatch, clsctx), userName)
> File "C:\Users\smcconnell\PycharmProjects\proficy\venv\
> lib\site-packages\win32com\client\dynamic.py", line 91, in
> _GetGoodDispatch
> IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
> pythoncom.IID_IDispatch)
> pywintypes.com_error: (-2147024156, 'The requested operation requires
> elevation.', None, None)
>
>
>
> If I run the script as administrator I get the following error:
>
>
> Traceback (most recent call last):
> File "C:\Users\smcconnell\PycharmProjects\proficy\venv\
> lib\site-packages\win32com\client\dynamic.py", line 89, in
> _GetGoodDispatch
> IDispatch = pythoncom.connect(IDispatch)
> pywintypes.com_error: (-2147221021, 'Operation unavailable', None, None)
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
> File "C:\Users\smcconnell\PycharmProjects\proficy\src\proficy.py", line
> 5, in <module>
> o = win32com.client.Dispatch("CimplicityME.Application")
> File "C:\Users\smcconnell\PycharmProjects\proficy\venv\
> lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
> dispatch, userName = dynamic._GetGoodDispatchAndUserName(
> dispatch,userName,clsctx)
> File "C:\Users\smcconnell\PycharmProjects\proficy\venv\
> lib\site-packages\win32com\client\dynamic.py", line 114, in
> _GetGoodDispatchAndUserName
> return (_GetGoodDispatch(IDispatch, clsctx), userName)
> File "C:\Users\smcconnell\PycharmProjects\proficy\venv\
> lib\site-packages\win32com\client\dynamic.py", line 91, in
> _GetGoodDispatch
> IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
> pythoncom.IID_IDispatch)
> pywintypes.com_error: (-2146959355, 'Server execution failed', None, None)
>
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> https://mail.python.org/mailman/listinfo/python-win32
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20180609/89588daf/attachment.html>
More information about the python-win32
mailing list