Click here to Skip to main content
1,837 members
Articles / Multimedia / C++

Searching for a reliable hardware ID

Rate me:
Please Sign up or sign in to vote.
4.90/5 (9 votes)
5 Jun 2012CPOL 51.1K   64   12   10
How a computer can be identified in order to generate a unique ID.

Introduction

Many desktop application developers need to uniquely identify the computer in which their software is running on. Such identification must produce a unique data element which will be different per each computer and will reproduce the same ID on any given computer.

The WMI set of classes

Windows provides a set of classes that can be used for most hardware enumeration and identification tasks, which is named WMI or Windows Management Instrumentation. These are extensions to the Windows Driver Model (WDM).

WMI provides per instrumented component static information and dynamic notification about any changes. Most programming languages can be used to manage, locally and remotely, computers and servers, enumerating their instrumented components and alerted for changes that occur.

During my research, I came to the conclusion that if speed and reliability is important, it is better to access hardware via the Win32 API and not use WMI. I have experienced many delays and in some occasions, WMI failed to detect an element such as the CPU ID.

This article focuses on the direct approach for obtaining this data without using WMI.

Obtaining a unique CPU ID

The solution that seems to be the best choice is to sample the CPU unique identification number (or CPU ID). However, there are several problems that makes it impossible to rely on reading the CPU ID.

To begin with, most CPUs with the exception of the old Pentium 3, don't have a unique CPU Serial Number. Intel has removed this feature for privacy reasons.

It is still possible to generate a unique ID from the motherboard as a whole. That certainly works but the huge number of different types of motherboards and manufacturers makes it next to impossible to generate a unique ID that will cover all of them.

In fact, a French company named CPU ID, focuses in this field and spends a lot of resources in getting to learn each type of motherboard and CPU, in order to cover them all.

The following screenshot shows the details that can be collected per each machine.

Image 1

Their SDK can be downloaded here, and can be used both as a static library (per special request) or a DLL with any application developed. The bad news is that even the guys from CPUID say it is impossible to generate a unique hardware ID based on the CPU or the motherboard of a given machine.

MAC address based hardware ID

The next choice for obtaining such a unique ID would be sampling the MAC address. To begin with, what is the "MAC address"? It stands for Media Access Control. The MAC address is 48 bits long (6 bytes). The GetMACAddress code sample explains how to obtain the MAC address.

However, there is one problem with this approach: the MAC address can be easily changed into a new one...

Hard Drive serial number

It seems that the only reliable solution for obtaining a machine ID would be using the serial number of the main Hard Drive. The second example, GetHDSerialNumber, shows how to obtain this ID. From my experience, this approach is the best one and the most reliable for generating a unique machine based hardware ID.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Michael Haephrati
United States United States
Michael Haephrati, born in 1964, an entrepreneur, inventor and a musician. Haephrati worked on many ventures starting from HarmonySoft, designing Rashumon, the first Graphical Multi-lingual word processor for Amiga computer.

Worked with Amdocs and managed several software projects, among them one for the Ministry of Tourism in New Zealand. During 1995-1996 he worked as a Contractor with Apple at Cupertino. After returning to Israel, worked as a Project Manager with Top Image Systems (mostly with JCC, Nicosia), and then at a research institute made the fist steps developing the credit scoring field in Israel. He founded Target Scoring and developed a credit scoring system named ThiS, based on geographical statistical data, participating VISA CAL, Isracard, Bank Leumi and Bank Discount (Target Scoring, being the VP Business Development of a large Israeli institute).
During 2000, he founded Target Eye, and developed the first remote PC surveillance and monitoring system, named Target Eye.

Other ventures included: Data Cleansing (as part of the DataTune system which was implemented in many organizations.


Also a Code Project Member since Sunday, March 16, 2003 (10 years, 5 months)
20 Sep 2013: Best C++ article of August 2013
25 Jan 2013: Code Project - Best C++ article of December 2012
31 Dec 2012: CodeProject MVP 2013

Comments and Discussions

 
GeneralAnother ID I ran across Pin
ledtech314-Dec-13 6:28
ledtech314-Dec-13 6:28 
GeneralMy vote of 5 Pin
John Walles29-Aug-13 2:31
John Walles29-Aug-13 2:31 
GeneralRe: My vote of 5 Pin
Michael Haephrati8-Sep-13 5:58
Michael Haephrati8-Sep-13 5:58 
GeneralYou still have a problem Pin
KChandos24-Aug-12 10:58
KChandos24-Aug-12 10:58 
GeneralRe: You still have a problem Pin
Michael Haephrati8-Sep-13 6:02
Michael Haephrati8-Sep-13 6:02 
My article doesn't presume any "phone home" process. A reliable ID, and a reliable process for obtaining it, should not rely on connecting to the Internet. Also, I haven't discuss any in-app process of doing any kind of manipulation with the data, but just raised the question of how to obtain the main building block which is a unique number which will not change and can not be forged. To answer your question, based on my outcome, the hard drive manufacturer serial number is the most reliable source for such ID and that creates a problem if the hard drive is replaced or broken, but software companies who use this approach, know how to handle and reassign a new hardware ID in such case.
GeneralHarddrive Serial Numbers Pin
ledtech35-Jun-12 6:52
ledtech35-Jun-12 6:52 
GeneralRe: Harddrive Serial Numbers Pin
Michael Haephrati8-Sep-13 6:03
Michael Haephrati8-Sep-13 6:03 
GeneralRe: Harddrive Serial Numbers Pin
ledtech38-Sep-13 8:06
ledtech38-Sep-13 8:06 
GeneralRe: Harddrive Serial Numbers Pin
Michael_Haephrati12-Sep-13 8:42
Michael_Haephrati12-Sep-13 8:42 
GeneralRe: Harddrive Serial Numbers Pin
ledtech312-Sep-13 13:06
ledtech312-Sep-13 13:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.