How to get CPU ID?

How to get the CPU ID and display it in a text control when I started my VC++ program?

Notice the CPU ID I mean here is like the host ID in UNIX which was generated with the command "hostid".

Who is Participating?
jhattinghConnect With a Mentor Commented:
There is no such id. If you want to protect software or generate a unique ID, use the volume serial number:

      char lpszVolumeName[255];
      char lpszFileSystemName[255];
      DWORD dwFlags=0, dwSerialNo = 0;
      LPCTSTR lpszPath = "C:\\";
      DWORD dwMaxLength=0;

      if (GetVolumeInformation("C:\\", lpszVolumeName, 255, &dwSerialNo, &dwMaxLength, &dwFlags, lpszFileSystemName, 255))
            m_strSerialNo.Format("Serial No:\n%d", dwSerialNo);
There is no such ID in windows.  If you are on a network, the network card has a unique ID.
you can also get the hard drive Id.  This is often used for seding the random number generator, or generating a unique user Id.  Perhpas you could tell us what you are trying to achieve?
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

You can use the IP address of the machine if you are on a network and convert that to a hexadecimal number.
It think the best approach to use is to generate a
CLSID for each machine. You can put it somewhere in the registry. The CLSID will ensure uniqueness because it based on a OSF DCE algorithm.
phillipluAuthor Commented:
Thank you very much!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.