2

In an application, it needs to retrieve, a system specific UniqueId. SO that I have tried to retrive the UniqueId of the CPU. and I am using WMI class property to retrieve that. But on trying to retrieve the 'UniqueId' property of win32_processor class, it returns VT_NULL in the variant in which the output is expected. But in the same time it is providing valid outputs for other properties like, deciveId, processorId etc. but those are not unique and can't fulfil my purpose.

Any one know why this happens? plz help me....

below is the code that i used... please have a look, and say whether there is any problem in that.... what modification can i do to make it work...

   if(CoInitializeSecurity( NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE,
0
) != S_OK)
    return;

IWbemLocator * pIWbemLocator = NULL;
IWbemServices * pWbemServices = NULL;
IEnumWbemClassObject * pEnumObject  = NULL;

BSTR bstrNamespace = (L"root\\cimv2");


if(CoCreateInstance (
        CLSID_WbemAdministrativeLocator,
        NULL ,
        CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER , 
        IID_IUnknown ,
        ( void ** ) & pIWbemLocator
        ) != S_OK)
            return;

if(pIWbemLocator->ConnectServer(
            bstrNamespace,  // Namespace
            NULL,          // Userid
            NULL,           // PW
            NULL,           // Locale
            0,              // flags
            NULL,           // Authority
            NULL,           // Context
            &pWbemServices
            ) != S_OK)
            return;



HRESULT hRes;
BSTR strQuery = (L"Select * from Win32_Processor");
BSTR strQL = (L"WQL");
hRes = pWbemServices->ExecQuery(strQL, strQuery,WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject);

if(hRes != S_OK)
{
    MessageBox("Could not execute Query");
    return;
}

ULONG uCount = 1, uReturned;
IWbemClassObject * pClassObject = NULL;


hRes = pEnumObject->Reset();

if(hRes != S_OK)
{
    MessageBox("Could not Enumerate");
    return;
}

hRes = pEnumObject->Next(WBEM_INFINITE,uCount, &pClassObject, &uReturned);
if(hRes != S_OK)
{
    MessageBox("Could not Enumerate");
    return;
}

VARIANT v;


BSTR strClassProp = SysAllocString(L"UniqueId");

hRes = pClassObject->Get(strClassProp, 0, &v, 0, 0);// here the v is VT_NULL but works if the vlaue of strClassProp is processerId, deviceId
if(hRes != S_OK)
{
    MessageBox("Could not Get Value");
    return;
}

SysFreeString(strClassProp);

_bstr_t bstrPath = &v;  //it causes exception if the v is VT_NULL in other cases its working

char* strPath = new char [1024];
_stprintf(strPath, ("%s"),(char*)bstrPath);


if (SUCCEEDED(hRes))
    MessageBox(strPath);

Expects expert advice and help.... Thanks in Advance....

JijeshKV
  • 670
  • 2
  • 7
  • 26
  • The computer might be configured *not* to reveal the processor id. Some people believe this is a matter of privacy, and don't want to be uniquely identified. – Bo Persson Oct 08 '12 at 09:48
  • u mean that it can be restricted by system settings? if the system restricts, we cant retrieve that? – JijeshKV Oct 08 '12 at 09:53
  • Something like that, yes. If it is your own computer, you might check the BIOS settings. – Bo Persson Oct 08 '12 at 09:56
  • 1
    The unique id feature doesn't exist in modern Intel x86 CPUs. http://en.wikipedia.org/wiki/Processor_Serial_Number#Controversy_about_privacy_issues – João Augusto Oct 08 '12 at 10:07
  • thank u Bo Persson and Joao Ausustano for your valuable comments... is there any alternative to find a unique Id to distinguish a pc? (other than MAC adress as it may change on changing the n/w card) – JijeshKV Oct 08 '12 at 10:12
  • You could try to use the CryptProtectData function to encrypt a "text" (ex. "this is unique for a machine") using the CRYPTPROTECT_LOCAL_MACHINE flag, the output of the function can probably be your unique Id... – João Augusto Oct 08 '12 at 10:59
  • If you need a unique identifier, then UuidCreate should work: it gives you a 128-bit GUID that's guaranteed to be globally unique if the function returns RPC_S_OK. If that's not sufficient, then I would suggest you rethink your design and the requirements; if you still think you need a globally unique ID and feel that a GUID from UuidCreate isn't sufficient, you'll need to tell us why and explain what you're trying to do so we can try to help. – Nik Bougalis Oct 17 '12 at 17:19
  • Hi Nik thanks for ur comment.. but the GUID can't workd out in my case... I need a unique ID but it should be machine specific. that means I need that again when my application run in that machine. my purpose is to distinguish the machines that my application runs... – JijeshKV Oct 22 '12 at 12:35
  • In case you need a unique id from every machine, why not try the SerialNumber in Win32_BIOS. That returns a static unique value for every individual machine, and the value won't change (unless someone changes the motherboard) – CuccoChaser Nov 16 '12 at 11:00

0 Answers0