Why this code generates different numbers?

Posted by frbry on Stack Overflow See other posts from Stack Overflow or by frbry
Published on 2010-05-20T08:23:10Z Indexed on 2010/05/20 8:30 UTC
Read the original article Hit count: 302

Filed under:
|
|
|

Hello,

I have this function that creates a unique number for hard-disk and CPU combination.

DWORD hw_hash()
{
    char drv[4];
    char szNameBuffer[256];
    DWORD dwHddUnique;
    DWORD dwProcessorUnique;
    DWORD dwUniqueKey;

    char *sysDrive = getenv ("SystemDrive");

    strcpy(drv, sysDrive);
    drv[2] = '\\';
    drv[3] = 0;
    GetVolumeInformation(drv, szNameBuffer, 256, &dwHddUnique, NULL, NULL, NULL, NULL);

    SYSTEM_INFO si;
    GetSystemInfo(&si);

    dwProcessorUnique = si.dwProcessorType + si.wProcessorArchitecture + si.wProcessorRevision;
    dwUniqueKey = dwProcessorUnique + dwHddUnique;

    return dwUniqueKey;
}

It returns different numbers if I format my hard-disk and install a new Windows. Any ideas, why?

Thank you.

Edit:

OK, Got it:

This function returns the volume serial number that the operating system assigns when a hard disk is formatted. To programmatically obtain the hard disk's serial number that the manufacturer assigns, use the Windows Management Instrumentation (WMI) Win32_PhysicalMedia property SerialNumber.

I should do more research before posting my problems online. Sorry to bother you, let's keep this here in case anybody else can need it.

© Stack Overflow or respective owner

Related posts about uniqueidentifier

Related posts about harddrive