diff --git a/tests/test_system.py b/tests/test_system.py index 4aeb6ef..5340f2e 100644 --- a/tests/test_system.py +++ b/tests/test_system.py @@ -27,6 +27,18 @@ class TestSystemWithCheckGarbage(object): return windows.system.logicaldrives def test_wmi(self): + # Well, pytest initialize COM with its own parameters + # It might make our own com.init() in WMI fail and therefore not call + # CoInitializeSecurity. But looks like pytest/default COM-security parameters + # does not allow to perform the request we want.. + # So we try & do it ourself here. + + # Do co-reinit in conftest.py ? + try: + if windows.com.init(): # if init fail. Call CoInitializeSecurity ourself + windows.com.initsecurity() + except Exception as e: + pass return windows.system.wmi.select("Win32_Process", "*") def test_handles(self): diff --git a/windows/com.py b/windows/com.py index ba5cfda..d2213ca 100644 --- a/windows/com.py +++ b/windows/com.py @@ -17,9 +17,14 @@ from windows.generated_def.interfaces import generate_IID, IID def init(): try: - winproxy.CoInitializeEx() + t = winproxy.CoInitializeEx() except WindowsError as e: - return e.winerror + t = e.winerror + if t: + return t + return initsecurity() + +def initsecurity(): # Should take some parameters.. return winproxy.CoInitializeSecurity(0, -1, None, 0, 0, RPC_C_IMP_LEVEL_IMPERSONATE, 0,0,0) diff --git a/windows/winobject/wmi.py b/windows/winobject/wmi.py index 4345217..56d41ce 100644 --- a/windows/winobject/wmi.py +++ b/windows/winobject/wmi.py @@ -24,6 +24,7 @@ class WmiRequester(object): windows.com.init() windows.com.create_instance(WbemLocator_CLSID, locator) + # WBEM_FLAG_CONNECT_USE_MAX_WAIT locator.ConnectServer(target, user, password , None, 0x80, None, None, ctypes.byref(service)) self.service = service