1

How to get the unique number (serial number/ID) for Processor (CPU), SCSI, Display, and IDE using C++ program other than WMI and asm code?

zeFree
  • 2,129
  • 2
  • 31
  • 39

3 Answers3

3

Since you mention WMI, I assume you are working on Windows. Lookup GetVolumeInformation().

Éric Malenfant
  • 13,938
  • 1
  • 40
  • 42
  • this sounds like something for licensing software, GetVolumeInformation() return the volume serial that changes every time the disk is formatted and is trivial change in software. The manufacturer serial would be more helpful. –  Oct 23 '09 at 13:34
1

On Windows you can get CPU info from the environment variable *PROCESSOR_** , you can parse the volume serial number from vol, the MAC address from route print

If you want to make it cross-platform (and if this is for software licensing) then an open source platform like Linux raises the problem to a whole new level anyway and requires a different approach. However you can still get a lot of the info by parsing the output from standard tools.

You really should consider WMI. In the old days, the BIOS would have been helpful but its all been replaced by the HAL.

CodeProject is always worth searching in cases like this.

How To Get Hardware Information

1

The below is the code I use to retrieve the hard drive serial for a game, so that cheaters are permanently banned (and they can't get back in without getting a new drive!):

string GetMachineID()
{
    // LPCTSTR szHD = "C:\\";  // ERROR
    string ss;
    ss = "Err_StringIsNull";
    UCHAR szFileSys[255],
        szVolNameBuff[255];
    DWORD dwSerial;
    DWORD dwMFL;
    DWORD dwSysFlags;
    int error = 0;

    bool success = GetVolumeInformation(LPCTSTR("C:\\"), (LPTSTR)szVolNameBuff,
        255, &dwSerial,
        &dwMFL, &dwSysFlags,
        (LPTSTR)szFileSys,
        255);
    if (!success) {
        ss = "Err_Not_Elevated";
    }
    std::stringstream errorStream;
    errorStream << dwSerial;
    return string(errorStream.str().c_str());
}

Although there is a potential bug whereupon if Windows is installed onto a drive other than C:\, this is an easy fix.

AStopher
  • 4,207
  • 11
  • 50
  • 75
  • WARNING! Instead of hard drive serial number this solution gives you volume serial number which is quite different. – Just Shadow Feb 10 '18 at 15:40
  • @JustShadow It's not possible to retrieve the *actual* hard drive serial number in Windows without using specialist tools for each manufacturer. This retrieves the "serial number" that Windows gives you as the drive serial, therefore this answer is valid. – AStopher Feb 10 '18 at 16:58
  • Here is complete solution: https://stackoverflow.com/questions/24049367/how-do-i-get-the-disk-drive-serial-number-in-c-c/48741695#48741695 It wraps WMI calls, and no additional tools required – Just Shadow Feb 12 '18 at 07:51