Fix a bug in com.init() when CoInitializeEx failed + fix test: test_wmi fail du to pytest default COM-security settings

This commit is contained in:
hakril
2018-03-04 18:34:40 +01:00
parent a057f8c130
commit d91bc1a45a
3 changed files with 20 additions and 2 deletions
+12
View File
@@ -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):
+7 -2
View File
@@ -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)
+1
View File
@@ -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