本文整理汇总了C++中IEnumWbemClassObject::Release方法的典型用法代码示例。如果您正苦于以下问题:C++ IEnumWbemClassObject::Release方法的具体用法?C++ IEnumWbemClassObject::Release怎么用?C++ IEnumWbemClassObject::Release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumWbemClassObject
的用法示例。
在下文中一共展示了IEnumWbemClassObject::Release方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsOHMRunning
bool CHardwareMonitor::IsOHMRunning()
{
if ((m_pServicesOHM == NULL) || (m_pServicesSystem == NULL))
return false;
bool bOHMRunning = false;
IEnumWbemClassObject* pEnumerator = NULL;
HRESULT hr;
hr = m_pServicesSystem->ExecQuery(L"WQL", L"Select * from win32_Process WHERE Name='OpenHardwareMonitor.exe'" , WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
if (SUCCEEDED(hr))
{
IWbemClassObject *pclsObj=NULL;
ULONG uReturn = 0;
hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
if ((FAILED(hr)) || (0 == uReturn))
{
pEnumerator->Release();
return false;
}
VARIANT vtProp;
VariantInit(&vtProp);
hr = pclsObj->Get(L"ProcessId", 0, &vtProp, 0, 0);
int procId = static_cast<int>(vtProp.iVal);
if (procId) {
bOHMRunning = true;
}
pclsObj->Release();
pEnumerator->Release();
}
return bOHMRunning;
}
示例2: TryAddress
static bool TryAddress(const std::string& ipAddress)
{
IEnumWbemClassObject* enumerator = 0;
std::wstring query(L"SELECT * FROM Win32_PingStatus WHERE (Address=\"");
query.append(::UTF8ToWide(ipAddress));
query.append(L"\")");
BSTR queryBstr = SysAllocString(query.c_str());
HRESULT result = service->ExecQuery(L"WQL", queryBstr,
WBEM_FLAG_FORWARD_ONLY, 0, &enumerator);
SysFreeString(queryBstr);
if (FAILED(result))
{
HandleHResultError("Failed to execute address query", result);
return false;
}
ULONG count;
IWbemClassObject* ping = 0;
result = enumerator->Next(WBEM_INFINITE, 1L, &ping, &count);
if (FAILED(result))
{
HandleHResultError("Failed to get ping data", result);
enumerator->Release();
return false;
}
if (count < 1)
{
LogError("Did not find ping result");
enumerator->Release();
ping->Release();
return false;
}
variant_t pingValue;
result = ping->Get(L"StatusCode", 0, &pingValue, 0, 0);
if (FAILED(result))
{
HandleHResultError("Could not get ping StatusCode value", result);
enumerator->Release();
ping->Release();
return false;
}
ping->Release();
return static_cast<int>(pingValue) == 0;
}
示例3: get_username
static int get_username() {
IEnumWbemClassObject *enumerator = 0;
IWbemClassObject * object = 0;
bool res = false;
_username = bstr_t();
enumerator = request(bstr_t("select UserName from Win32_ComputerSystem"));
VARIANT vUsername;
VariantInit(&vUsername);
ULONG uReturn;
for(;;) {
HRESULT result = enumerator->Next(WBEM_INFINITE, 1, &object, &uReturn);
if(uReturn == 0) {
break;
}
result = object->Get(L"UserName", 0, &vUsername, 0, 0);
if (SUCCEEDED(result)) {
_username = GetShortName(vUsername.bstrVal);
res = true;
}
object->Release();
}
if (enumerator)
enumerator->Release();
//std::cout << "get_username(): " << _username << std::endl;
return res;
}
示例4: readIpAddressesMsft
/**
* Enumerates MSFT_NetIpAddress whose interface index is the same as the
* adaptor's. Calls stringToAdaptorIP() for each object so that the
* highest priority IP address is associated with the adaptor.
*/
static void readIpAddressesMsft(IWbemServices *pNamespace, SFLAdaptor *adaptor)
{
BSTR queryLang = SysAllocString(L"WQL");
wchar_t *query = L"SELECT * FROM MSFT_NetIpAddress WHERE InterfaceIndex=%u";
wchar_t ipQuery[70];
swprintf_s(ipQuery, 70, query, adaptor->ifIndex);
IEnumWbemClassObject *ipEnum = NULL;
HRESULT hr = pNamespace->ExecQuery(queryLang, ipQuery, WBEM_FLAG_FORWARD_ONLY, NULL, &ipEnum);
SysFreeString(queryLang);
if (!SUCCEEDED(hr)) {
myLog(LOG_ERR,"readIpAddressesMsft: ExecQuery() failed for query %S error=0x%x", ipQuery, hr);
return;
}
IWbemClassObject *ipObj;
hr = WBEM_S_NO_ERROR;
while (WBEM_S_NO_ERROR == hr) {
ULONG ipCount = 0;
hr = ipEnum->Next(WBEM_INFINITE, 1, &ipObj, &ipCount);
if (ipCount == 0) {
break;
}
VARIANT address;
hr = ipObj->Get(L"IPAddress", 0, &address, 0, 0);
if (WBEM_S_NO_ERROR == hr && V_VT(&address) == VT_BSTR) {
stringToAdaptorIp(address.bstrVal, adaptor);
}
VariantClear(&address);
ipObj->Release();
}
ipEnum->Release();
}
示例5: associatorsOf
/**
* Finds the associated Win32_NetworkAdapterConfiguration for Win32_NetworkAdapter adapterObj.
* Iterates through the IP addresses associated with the adapter calling
* stringToAdaptorIp() to choose the highest priority address (according to EnumIPSelectionPriority)
* as the adapter address which is used to populate adapter->userData->ipAddr.
* If two addresses have the same highest priority, then the first one seen is chosen.
*/
static void readIpAddressesWin32(IWbemServices *pNamespace, IWbemClassObject *adapterObj, SFLAdaptor *adaptor)
{
IEnumWbemClassObject *configEnum;
HRESULT hr = associatorsOf(pNamespace, adapterObj,
L"Win32_NetworkAdapterSetting",
L"Win32_NetworkAdapterConfiguration",
L"Setting", &configEnum);
if (SUCCEEDED(hr)) {
IWbemClassObject *configObj;
ULONG configCount;
hr = configEnum->Next(WBEM_INFINITE, 1, &configObj, &configCount);
if (SUCCEEDED(hr) && configCount == 1) {
VARIANT addresses;
hr = configObj->Get(L"IPAddress", 0, &addresses, 0, 0);
if (WBEM_S_NO_ERROR == hr && addresses.vt == (VT_ARRAY | VT_BSTR)) {
SAFEARRAY *sa = V_ARRAY(&addresses);
LONG lstart, lend;
hr = SafeArrayGetLBound(sa, 1, &lstart);
hr = SafeArrayGetUBound(sa, 1, &lend);
BSTR *pbstr;
hr = SafeArrayAccessData(sa, (void HUGEP **)&pbstr);
if (SUCCEEDED(hr)) {
for (LONG idx=lstart; idx <= lend; idx++) {
PCWSTR addrStr = pbstr[idx];
stringToAdaptorIp(addrStr, adaptor);
}
SafeArrayUnaccessData(sa);
}
}
VariantClear(&addresses);
configObj->Release();
}
configEnum->Release();
}
}
示例6: queryByDeviceID
bool
IPodDetector::doesIpodExist(IPod *ipod)
{
IEnumWbemClassObject* enumerator = NULL;
std::stringstream output;
for( size_t i = 0; i < ipod->serial().length(); ++i )
{
output << (char)ipod->serial().c_str()[i];
}
queryByDeviceID( output.str(), &enumerator );
IWbemClassObject* object;
ULONG count;
enumerator->Next( WBEM_INFINITE, 1, &object, &count );
enumerator->Release();
if( count > 0 )
{
object->Release();
return true;
}
return false;
}
示例7: queryCurrentlyConnectedDevices
void
IPodDetector::checkConnectedDevices()
{
IEnumWbemClassObject* currentDevicesEnumerator = NULL;
queryCurrentlyConnectedDevices( ¤tDevicesEnumerator );
IWbemClassObject* device;
ULONG returnCount = 0;
while( currentDevicesEnumerator )
{
currentDevicesEnumerator->Next( WBEM_INFINITE,
1,
&device,
&returnCount );
if( 0 == returnCount )
{
break;
}
if( returnCount > 0 )
{
LOGL( 3, "Detected pre-connected iPod" );
onDeviceConnected( device );
}
device->Release();
}
currentDevicesEnumerator->Release();
}
示例8: MappingUsbstorToDeviceNumber
// (Usually internal) method to perform usb drive search
bool DeviceFinder::MappingUsbstorToDeviceNumber(std::map<std::string, int>& usbStorToDeviceMap)
{
HRESULT hr;
// Clear list of drive names
usbStorToDeviceMap.clear();
// Ensure pSvc is initialized
if (!Initialize()) { Log(0, "ERROR: Unable to initialize for usbstor-deviceNumber mapping.\n"); return false; }
// Use the IWbemServices pointer to make a WMI request for Win32_SerialPort
IEnumWbemClassObject* pEnumerator = NULL;
IWbemServices *pServices = (IWbemServices *)pSvc; // Cast required as the public API doesn't include the type information
if (pServices == NULL) { Log(0, "ERROR: Unable to get usbstor-deviceNumber mapping.\n"); return false; }
hr = pServices->ExecQuery(bstr_t("WQL"), bstr_t("SELECT PNPDeviceID, DeviceID FROM Win32_DiskDrive WHERE InterfaceType='USB'"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
if (FAILED(hr)) { Log(0, "ERROR: Query for Win32_DiskDrive has failed: 0x%08x\n", hr); return false; }
// Get the data from the query
if (pEnumerator)
{
for (;;)
{
// Get next item in enumeration
IWbemClassObject *pclsObj;
ULONG uReturn = 0;
hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
// If no more items, exit loop
if (uReturn == 0) { break; }
// Get value of the "PNPDeviceID" property
VARIANT vtProp;
hr = pclsObj->Get(L"PNPDeviceID", 0, &vtProp, 0, 0);
char usbstorId[256] = { 0 };
wcstombs_s(NULL, usbstorId, vtProp.bstrVal, 255); // Convert to ASCII
VariantClear(&vtProp);
//cerr << "[DRIVE:USBSTOR] " << usbstorId << endl;
// Get value of the "DeviceID" property
hr = pclsObj->Get(L"DeviceID", 0, &vtProp, 0, 0);
char deviceId[256] = { 0 };
wcstombs_s(NULL, deviceId, vtProp.bstrVal, 255); // Convert to ASCII
unsigned int deviceNumber = GetDeviceNumber(vtProp.bstrVal);
VariantClear(&vtProp);
//cerr << "[DRIVE:DEVICEID] " << deviceId << endl;
//cerr << "[DRIVE:DEVICENUMBER] " << deviceNumber << endl;
//DiskDriveToLogicalDrive(deviceId);
#ifdef DEBUG_PRINT
Log(3, "[USBSTOR->DEVICEID->DEVICENUMBER] %s -> %s -> %u\n", usbstorId, deviceId, deviceNumber);
#endif
usbStorToDeviceMap[usbstorId] = deviceNumber;
pclsObj->Release();
}
pEnumerator->Release();
}
return true;
}
示例9: CoInitialize
/*
* Solution by: Simon Mourier
* From: http://stackoverflow.com/questions/5327203/how-to-access-cpus-heat-sensors
*
* For linking use: Wbemuuid.lib
* Running info: application must run under administrator privileges!
*/
double SystemInfo::DiagnosticMgr::getCpuTemp()
{
LONG result;
LPLONG pTemperature = &result;
*pTemperature = -1;
HRESULT ci = CoInitialize(NULL); // needs comdef.h
HRESULT hr = CoInitializeSecurity(NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE,
NULL, EOAC_NONE, NULL);
if (SUCCEEDED(hr))
{
IWbemLocator *pLocator; // needs Wbemidl.h & Wbemuuid.lib
hr = CoCreateInstance(CLSID_WbemAdministrativeLocator, NULL, CLSCTX_INPROC_SERVER , IID_IWbemLocator, (LPVOID*)&pLocator);
if (SUCCEEDED(hr))
{
IWbemServices *pServices;
BSTR ns = SysAllocString(L"root\\WMI");
hr = pLocator->ConnectServer(ns, NULL, NULL, NULL, 0, NULL, NULL, &pServices);
pLocator->Release();
SysFreeString(ns);
if (SUCCEEDED(hr))
{
BSTR query = SysAllocString(L"SELECT * FROM MSAcpi_ThermalZoneTemperature");
BSTR wql = SysAllocString(L"WQL");
IEnumWbemClassObject *pEnum;
hr = pServices->ExecQuery(wql, query, WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY, NULL, &pEnum);
SysFreeString(wql);
SysFreeString(query);
pServices->Release();
if (SUCCEEDED(hr))
{
IWbemClassObject *pObject;
ULONG returned;
hr = pEnum->Next(-1, 1, &pObject, &returned);
pEnum->Release();
if (SUCCEEDED(hr))
{
BSTR temp = SysAllocString(L"CurrentTemperature");
VARIANT v;
VariantInit(&v);
hr = pObject->Get(temp, 0, &v, NULL, NULL);
pObject->Release();
SysFreeString(temp);
if (SUCCEEDED(hr))
{
*pTemperature = V_I4(&v);
}
VariantClear(&v);
}
}
}
if (ci == S_OK)
{
CoUninitialize();
}
}
}
double tempInTensOfKelvins = (double)*pTemperature;
return (tempInTensOfKelvins > 0.0) ? ((double)*pTemperature / 10.0) - 273.15 : 0.0;
}
示例10: GetVideoCardDriverVersion
// Adapted mostly as-is from http://www.gamedev.net/topic/495075-how-to-retrieve-info-about-videocard/?view=findpost&p=4229170
// so credit goes to that post's author, and in turn, the author of the site mentioned in that post (which seems to be down?).
std::string GetVideoCardDriverVersion() {
std::string retvalue = "";
HRESULT hr;
hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (FAILED(hr)) {
return retvalue;
}
IWbemLocator *pIWbemLocator = NULL;
hr = CoCreateInstance(__uuidof(WbemLocator), NULL, CLSCTX_INPROC_SERVER,
__uuidof(IWbemLocator), (LPVOID *)&pIWbemLocator);
if (FAILED(hr)) {
CoUninitialize();
return retvalue;
}
BSTR bstrServer = SysAllocString(L"\\\\.\\root\\cimv2");
IWbemServices *pIWbemServices;
hr = pIWbemLocator->ConnectServer(bstrServer, NULL, NULL, 0L, 0L, NULL, NULL, &pIWbemServices);
if (FAILED(hr)) {
pIWbemLocator->Release();
SysFreeString(bstrServer);
CoUninitialize();
return retvalue;
}
hr = CoSetProxyBlanket(pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE,
NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL,EOAC_DEFAULT);
BSTR bstrWQL = SysAllocString(L"WQL");
BSTR bstrPath = SysAllocString(L"select * from Win32_VideoController");
IEnumWbemClassObject* pEnum;
hr = pIWbemServices->ExecQuery(bstrWQL, bstrPath, WBEM_FLAG_FORWARD_ONLY, NULL, &pEnum);
ULONG uReturned;
VARIANT var;
IWbemClassObject* pObj = NULL;
if (!FAILED(hr)) {
hr = pEnum->Next(WBEM_INFINITE, 1, &pObj, &uReturned);
}
if (!FAILED(hr) && uReturned) {
hr = pObj->Get(L"DriverVersion", 0, &var, NULL, NULL);
if (SUCCEEDED(hr)) {
char str[MAX_PATH];
WideCharToMultiByte(CP_ACP, 0, var.bstrVal, -1, str, sizeof(str), NULL, NULL);
retvalue = str;
}
}
pEnum->Release();
SysFreeString(bstrPath);
SysFreeString(bstrWQL);
pIWbemServices->Release();
pIWbemLocator->Release();
SysFreeString(bstrServer);
CoUninitialize();
return retvalue;
}
示例11: wmi_get_cpu_frequency
int wmi_get_cpu_frequency(float* pcpu_frequency) {
assert(_initialized);
assert(pcpu_frequency);
float& cpu_frequency = *pcpu_frequency;
IEnumWbemClassObject *enumerator = 0;
IWbemClassObject * object = 0;
// Use the IWbemServices pointer to make requests of WMI ----
static const bstr_t WQL = bstr_t("WQL");
static const bstr_t Query = bstr_t("SELECT CurrentClockSpeed FROM Win32_Processor");
HRESULT result = services->ExecQuery(WQL,
Query,
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&enumerator
);
if (FAILED(result)) {
log_err("Query for operating system name failed."
" Error code = %d \n", result);
services->Release();
locator->Release();
CoUninitialize();
//TODO return valid error
return -1;
}
VARIANT variant;
ULONG uReturn;
for(;;)
{
result = enumerator->Next(WBEM_INFINITE, 1, &object, &uReturn);
if(0 == uReturn) {
break;
}
VariantInit(&variant);
result = object->Get(L"CurrentClockSpeed", 0, &variant, 0, 0);
if (result == WBEM_S_NO_ERROR) {
//Variant::Print(variant);
cpu_frequency = (float)variant.iVal;
}
object->Release();
}
if (enumerator)
enumerator->Release();
return 0;
}
示例12: get_num_core
static int get_num_core() {
IEnumWbemClassObject *enumerator = 0;
IWbemClassObject * object = 0;
int res = -1;
_num_core = 0;
enumerator = request(bstr_t("select NumberOfCores from Win32_Processor"));
VARIANT vUsername;
VariantInit(&vUsername);
ULONG uReturn;
for(;;) {
HRESULT result = enumerator->Next(WBEM_INFINITE, 1, &object, &uReturn);
if(uReturn == 0) {
break;
}
result = object->Get(L"NumberOfCores", 0, &vUsername, 0, 0);
if (SUCCEEDED(result)) {
_num_core = vUsername.uiVal;
res = 0;
}
object->Release();
}
if (enumerator)
enumerator->Release();
//std::cout << "get_num_core(): " << _num_core << std::endl;
return res;
}
示例13: WMIquery
VARIANT* GpuCapabilitiesWindows::WMIquery(std::string wmiClass, std::string attribute) {
// Code based upon: "Example: Getting WMI Data from the Local Computer"
// http://msdn2.microsoft.com/en-us/library/aa390423.aspx
if (!isWMIinited()) {
LWARNING("WMI not initiated");
return 0;
}
HRESULT hres;
VARIANT* result = 0;
// Step 6: --------------------------------------------------
// Use the IWbemServices pointer to make requests of WMI ----
IEnumWbemClassObject* pEnumerator = NULL;
std::string query = "SELECT " + attribute + " FROM " + wmiClass;
hres = pWbemServices_->ExecQuery(
bstr_t("WQL"),
bstr_t(query.c_str()),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres)) {
LWARNING("ERROR: WMI query failed: " << query);
return 0;
}
// Step 7: -------------------------------------------------
// Get the data from the query in step 6 -------------------
IWbemClassObject* pclsObj = 0;
ULONG uReturn = 0;
if (pEnumerator) {
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if (uReturn) {
// Get the value of the attribute and store it in result
result = new VARIANT;
hr = pclsObj->Get(LPCWSTR(str2wstr(attribute).c_str()), 0, result, 0, 0);
}
}
if (!result) {
LWARNING("No WMI query result");
}
// Clean enumerator and pclsObject
if (pEnumerator)
pEnumerator->Release();
if (pclsObj)
pclsObj->Release();
return result;
}
示例14: CBasicException
std::shared_ptr<CHardware> CHardwareFactory::newOpticalDiscDrive() const
{
/*
* IWbemServices::ExecQuery http://msdn.microsoft.com/en-us/library/windows/desktop/aa392107%28v=VS.85%29.aspx
* IWbemClassObject::Next http://msdn.microsoft.com/en-us/library/windows/desktop/aa391453%28v=VS.85%29.aspx
* IWbemClassObject::Get http://msdn.microsoft.com/en-us/library/windows/desktop/aa391442%28v=VS.85%29.aspx
* Win32_CDROMDrive class http://msdn.microsoft.com/en-us/library/windows/desktop/aa394081%28v=VS.85%29.aspx
*
* Creating a WMI Application Using C++ http://msdn.microsoft.com/en-us/library/windows/desktop/aa389762%28v=VS.85%29.aspx
*/
IEnumWbemClassObject* enumerator = 0;
HRESULT hr = mWbemServices->ExecQuery(BSTR(L"WQL"), BSTR(L"SELECT * FROM Win32_CDROMDrive"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 0, &enumerator);
if (FAILED(hr))
{
throw CBasicException("ExecQuery failed");
}
std::list<std::string> opticalDriveList;
while(enumerator)
{
IWbemClassObject* obj = 0;
ULONG ret = 0;
hr = enumerator->Next(WBEM_INFINITE, 1, &obj, &ret);
if (ret == 0 || FAILED(hr))
{
break;
}
VARIANT vtProp;
hr = obj->Get(L"Caption", 0, &vtProp, 0, 0);
if (FAILED(hr))
{
continue;
}
opticalDriveList.push_back(CUtils::str2utf8(vtProp.bstrVal));
VariantClear(&vtProp);
obj->Release();
}
enumerator->Release();
return std::shared_ptr<CHardware>(new CHardware(CHardware::OPTICALDISCDRIVE, opticalDriveList));
}
示例15: testForHyperv
/**
* Test to see whether we are running on a system with Hyper-V enabled.
* We consider Hyper-V to be running (and can export per vm stats) if
* the Hyper-V related services (nvspwmi, vmm, vhdsvc) are running and
* we can access the WMI namespace root\virtualization (ie v1 for Win 2008).
* We do not check for the v2 namespace, since this is not required for
* per vm stats.
* The ability connect to the sFlow filter for export of packet samples
* and counter samples for the virtual switch is made separately.
*/
BOOL testForHyperv()
{
BSTR path = SysAllocString(WMI_CIMV2_NS);
HRESULT hr = S_FALSE;
IWbemServices *pNamespace = NULL;
hr = connectToWMI(path, &pNamespace);
SysFreeString(path);
if (WBEM_S_NO_ERROR != hr) {
myLog(LOG_ERR,"testForHyperv: connectToWMI failed for namespace %S", path);
return false;
}
//Test for Hyper-V services
BOOL gotHyperV = false;
BSTR queryLang = SysAllocString(L"WQL");
BSTR query = SysAllocString(L"SELECT * FROM Win32_Service WHERE Name=\"nvspwmi\" OR Name=\"vmms\" OR Name=\"vhdsvc\"");
IEnumWbemClassObject *serviceEnum = NULL;
hr = pNamespace->ExecQuery(queryLang, query, WBEM_FLAG_FORWARD_ONLY, NULL, &serviceEnum);
SysFreeString(query);
SysFreeString(queryLang);
if (WBEM_S_NO_ERROR != hr) {
myLog(LOG_ERR, "testForHyperv: ExecQuery() failed for %S error=0x%x", query, hr);
} else {
IWbemClassObject *serviceObj = NULL;
ULONG uReturned = 0;
BOOL gotHyperVSvc = false;
hr = serviceEnum->Next(WBEM_INFINITE, 1, &serviceObj, &uReturned);
if (SUCCEEDED(hr)) {
if (uReturned == 1) {
gotHyperVSvc = true;
serviceObj->Release();
}
}
serviceEnum->Release();
pNamespace->Release();
if (gotHyperVSvc) { //now check that we have the v1 virtualization namespace
CoUninitialize();
path = SysAllocString(WMI_VIRTUALIZATION_NS_V1);
hr = connectToWMI(path, &pNamespace);
SysFreeString(path);
if (WBEM_NO_ERROR == hr) {
gotHyperV = true;
pNamespace->Release();
}
}
}
CoUninitialize();
myLog(LOG_INFO, "testForHyperv: HyperV=%u", gotHyperV);
return gotHyperV;
}