I'm using visual c++ 2010.
Im trying to retrieve harddisk serial number using win32_physicalmedia or win32_diskdrive and it's working normally but on alot of pcs it displays the serial number more than once and sometimes with symbols and characters.
The code i'm using is as follow :
pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT SerialNumber FROM Win32_PhysicalMedia"), // or Win32_DiskDrive
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
IWbemClassObject *pclsObj;
ULONG uReturn = 0;
while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if(0 == uReturn)
{
break;
}
VARIANT vtProp;
hr = pclsObj->Get(L"SerialNumber", 0, &vtProp, 0, 0);
wcout << " Physical Drive SN : " << vtProp.bstrVal << endl;
VariantClear(&vtProp);
pclsObj->Release();
}
The result is sometimes like this :
Physical Drive SN : 325a323565222565226500
Physical Drive SN : 325a323565222565226500
Physical Drive SN : 3
Physical Drive SN : 3
Physical Drive SN : 3
Physical Drive SN : ♥
Physical Drive SN : ♥
As you can see the serial is correct but it's repeated twice in 2nd line and the other lines are showing symbols knowing that i have only 1 Hard Disk.
Please advise.
Ohh guys i guess after some researches i found out that the code is also trying to get serial number of all removable devices too not only the harddisk!!
Can anyone tell me how to specify the mediatype only to fixed hard disk ! ?