mirror of
https://github.com/hakril/PythonForWindows
synced 2026-06-08 14:31:45 +00:00
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:
@@ -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
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user