From 1053b83782f0eda617e36ed12a7fa227f6fa8b6c Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 17 Jun 2021 04:46:10 +0200 Subject: [PATCH] Fixing wmi issue when device detection thread run nth time --- wmi/wmi.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/wmi/wmi.cpp b/wmi/wmi.cpp index 5785c74e..f2de70dd 100644 --- a/wmi/wmi.cpp +++ b/wmi/wmi.cpp @@ -147,6 +147,14 @@ HRESULT Wmi::query(std::string queryStr, std::vector& queryVectorOut, int nIdx = 0; IEnumWbemClassObject* pEnumerator = nullptr; + // Initialize COM. ------------------------------------------ + hres = CoInitializeEx(0, COINIT_MULTITHREADED); + if (FAILED(hres)) + { + return hres; + } + + pSvc->Release(); // Reconnect to server before each query as we were seeing disconnected failures hres = pLoc->ConnectServer( _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace