OK I found the solution
IEnumWbemClassObject* pEnumerator = NULL;
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_OperatingSystem"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres))
{
std::cout << "Query for operating system name failed."
<< " Error code = 0x"
<< std::hex << hres << std::endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
IWbemClassObject *pclsObj;
ULONG uReturn = 0;
while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if(0 == uReturn)
{
break;
}
VARIANT vtProp;
std::cout << "----------------------------------" << std::endl;
std::cout << "Retrieve OS Info" << std::endl;
std::cout << "----------------------------------" << std::endl;
// Get the value of the Name property
hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
std::wcout << " OS Name : " << vtProp.bstrVal << std::endl;
VariantClear(&vtProp);
hr = pclsObj->Get(L"Version", 0, &vtProp, 0, 0);
std::wcout << " OS Version : " << vtProp.bstrVal << std::endl;
VariantClear(&vtProp);
hr = pclsObj->Get(L"WindowsDirectory", 0, &vtProp, 0, 0);
std::wcout << " OS Directory : " << vtProp.bstrVal << std::endl;
VariantClear(&vtProp);
pclsObj->Release();
}
pEnumerator->Release();
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_DiskDrive"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres))
{
std::cout << "Query for operating system name failed."
<< " Error code = 0x"
<< std::hex << hres << std::endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
uReturn = 0;
while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if(0 == uReturn)
{
break;
}
VARIANT vtProp;
std::cout << "----------------------------------" << std::endl;
std::cout << "Retrieve DISK Info" << std::endl;
std::cout << "----------------------------------" << std::endl;
// Get the value of the Name property
hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
std::wcout << " Disk Name : " << vtProp.bstrVal << std::endl;
VariantClear(&vtProp);
hr = pclsObj->Get(L"Model", 0, &vtProp, 0, 0);
std::wcout << " Disk Model : " << vtProp.bstrVal << std::endl;
VariantClear(&vtProp);
hr = pclsObj->Get(L"Status", 0, &vtProp, 0, 0);
std::wcout << " Status : " << vtProp.bstrVal << std::endl;
VariantClear(&vtProp);
hr = pclsObj->Get(L"DeviceID", 0, &vtProp, 0, 0);
std::wcout << " Device ID : " << vtProp.bstrVal << std::endl;
VariantClear(&vtProp);
hr = pclsObj->Get(L"SerialNumber", 0, &vtProp, 0, 0);
std::wcout << " SerialNumber : " << vtProp.bstrVal << std::endl;
VariantClear(&vtProp);