tags:

views:

538

answers:

0

The following C++ code to retrieve the motherboard info via WMI works on most machines, except one:

IEnumWbemClassObject* pEnumerator = NULL;
hres = pSvc->ExecQuery(
 bstr_t("WQL"), 
 bstr_t("Select  *  from  Win32_BaseBoard"),
 WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 
 NULL,
 &pEnumerator);

if (FAILED(hres))
{
 // handle error, exit
}
IWbemClassObject *pclsObj = NULL;
ULONG uReturn = 0;
while (pEnumerator)
{
 HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 
  &pclsObj, &uReturn);

 if(0 == uReturn)
 {
  break;
 }
 VARIANT vtProp;

 hr = pclsObj->Get(L"Product", 0, &vtProp, 0, 0);
 std::wstring productNo = vtProp.bstrVal;
    // do stuff with productNo
}

Specifically, pEnumerator->Next() returns 0, and therefore pclsObj is left NULL.

Have you ever run into a situation where a WMI query on Win32_BaseBoard returns no entries?