Skip to content

Commit 5ec8e39

Browse files
author
Yann MAHE
committed
[wmi] set provider architecture when necessary
On Windows 2008, setting a WMI provider would cause an exception. To prevent this from unecessarily happening, only proceed when the provided value is not set to the default one.
1 parent aff0a46 commit 5ec8e39

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

checks/libs/wmi/sampler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,16 +334,17 @@ def get_connection(self):
334334
# shouldn't be used in other threads (can lead to memory/handle leaks if done
335335
# without a deep knowledge of COM's threading model). Because of this and given
336336
# that we run each query in its own thread, we don't cache connections
337-
context = None
337+
additional_args = []
338338
pythoncom.CoInitialize()
339339

340340
if self.provider != ProviderArchitecture.DEFAULT:
341341
context = Dispatch("WbemScripting.SWbemNamedValueSet")
342342
context.Add("__ProviderArchitecture", self.provider)
343+
additional_args = [None, "", 128, context]
343344

344345
locator = Dispatch("WbemScripting.SWbemLocator")
345346
connection = locator.ConnectServer(
346-
self.host, self.namespace, self.username, self.password, None, "", 128, context
347+
self.host, self.namespace, self.username, self.password, *additional_args
347348
)
348349

349350
return connection

0 commit comments

Comments
 (0)