[python-win32] win32com.client.WithEvents fails when running as a Windows service
Hi, I'm trying to automate CANoe using win32com. I've written a script that works perfectly when I log in and run it as a normal user. I want to run it from a Jenkins service though and I have allowed the Jenkins service to interact with desktop or whatever that option is called. This runs just fine : myCanApp = win32com.client.Dispatch('CANoe.Application') print("CANoe dispatched!") And a CANoe instance is started. But then this code follows: onfiguration = myCanApp.Configuration measurement = myCanApp.Measurement # Getting the Test Configurations TestEnvs = Configuration.TestSetup.TestEnvironments csbTstMod = None for tstEnv in TestEnvs: if (tstEnv.Name != tstEnvName): continue tstEnv = win32com.client.CastTo(tstEnv, "ITestEnvironment2") for tstMod in tstEnv.TestModules: if (tstMod.Name == tstModName): csbTstMod = tstMod break win32com.client.WithEvents(csbTstMod, TestModuleEvents) Normally this also runs fine and I can intercept the events with my custom handler. When being run as a service though I get this error: Traceback (most recent call last): File "D:\Jenkins\Scripts\dispatch.py", line 203, in exec_test(PDConfigPath, "CommonTests", "PD_CSB") File "D:\Jenkins\Scripts\dispatch.py", line 146, in exec_test win32com.client.WithEvents(csbTstMod, TestModuleEvents) File "C:\Program Files\Python39\lib\site-packages\win32com\client\__init__.py", line 336, in WithEvents instance = result_class(disp) # This only calls the first base class __init__. File "C:\WINDOWS\TEMP\gen_py\3.9\7F31DEB0-5BCC-11D3-8562-00105A3E017Bx0x1x58.py", line 19507, in __init__ cookie=cp.Advise(win32com.server.util.wrap(self, usePolicy=EventHandlerPolicy)) pywintypes.com_error: (-2147024891, 'Access is denied.', None, None) It would be really useful to understand what's going on, where the problem is as I cannot determine what permissions I need to enable ( some COM permissions ? ) for this to work as a service. As I've said interact with Desktop is on , othewise the first Dispatch of CANoe wouldn't work. I'm using the latest pywin32 installed with pip ( as Admin ) in Windows 10 ver 19xx. Any help to make any progress or debug this somehow would be appreciated. I can debug using pydevd but so far that wasn't very useful. Thanks. ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] win32com.client.WithEvents fails when running as a Windows service
On Mar 6, 2021, at 6:43 AM, Marius Cirsta wrote: > > I'm trying to automate CANoe using win32com. I've written a script that > works perfectly when I log in and run it as a normal user. > ... > When being run as a service though I get this error: > > Traceback (most recent call last): > File "D:\Jenkins\Scripts\dispatch.py", line 203, in > exec_test(PDConfigPath, "CommonTests", "PD_CSB") > File "D:\Jenkins\Scripts\dispatch.py", line 146, in exec_test > win32com.client.WithEvents(csbTstMod, TestModuleEvents) > File "C:\Program > Files\Python39\lib\site-packages\win32com\client\__init__.py", line 336, in > WithEvents > instance = result_class(disp) # This only calls the first base class > __init__. > File > "C:\WINDOWS\TEMP\gen_py\3.9\7F31DEB0-5BCC-11D3-8562-00105A3E017Bx0x1x58.py", > line 19507, in __init__ > cookie=cp.Advise(win32com.server.util.wrap(self, > usePolicy=EventHandlerPolicy)) > pywintypes.com_error: (-2147024891, 'Access is denied.', None, None) Do you have your service configured to run as your user? The normal service user has different access permissions, so it can’t access your file shares. — Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32