Click here to Skip to main content
15,888,351 members
Articles / Programming Languages / C++

Searching for a Reliable Hardware ID

Rate me:
Please Sign up or sign in to vote.
4.93/5 (106 votes)
26 Mar 2020CPOL3 min read 285.9K   17.7K   212   143
How a computer can be identified in order to generate a unique ID
Many desktop application developers need to uniquely identify the computer on which their software is running. This article will show you how it can be done.

Introduction

Many desktop application developers need to uniquely identify the computer on which their software is running. 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.  Note: there is also an excellent article focusing on the BIOS UUID. The article was written by .

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 III, 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 for 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.

I would like to add that the serial number to be used, must be the one set by the manufacturer as opposed to the one set (and which can be changed) by the Operating System.

History

  • 28th January, 2015: Initial version

License

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


Written By
CEO Secured Globe, Inc.
United States United States
Michael Haephrati is a music composer, an inventor and an expert specializes in software development and information security, who has built a unique perspective which combines technology and the end user experience. He is the author of a the book Learning C++ , which teaches C++ 20, and was published in August 2022.

He is the CEO of Secured Globe, Inc., and also active at Stack Overflow.

Read our Corporate blog or read my Personal blog.





Comments and Discussions

 
GeneralRe: My vote of 5 Pin
Matan joice24-Jan-12 20:22
Matan joice24-Jan-12 20:22 
GeneralRe: My vote of 5 Pin
Michael Haephrati24-Jan-12 21:40
professionalMichael Haephrati24-Jan-12 21:40 
GeneralMessage Closed Pin
24-Jan-12 9:27
Emilio Garavaglia24-Jan-12 9:27 
GeneralRe: My vote of 2 Pin
Tibor Blazko1-Feb-12 10:25
Tibor Blazko1-Feb-12 10:25 
GeneralRe: My vote of 2 Pin
Michael Haephrati1-Feb-12 10:28
professionalMichael Haephrati1-Feb-12 10:28 
GeneralRe: My vote of 2 Pin
Tibor Blazko1-Feb-12 10:33
Tibor Blazko1-Feb-12 10:33 
GeneralRe: My vote of 2 Pin
Michael Haephrati1-Feb-12 10:38
professionalMichael Haephrati1-Feb-12 10:38 
QuestionThe never ending story Pin
Emilio Garavaglia24-Jan-12 9:21
Emilio Garavaglia24-Jan-12 9:21 
Why software need to know what computer it runs on?

Is the concept of "computer" uniquely identifiable?
Has the user the full right to change a broken had disk and restore his backed up data on the new one?
Has the user the full right of re-install the computer operating system in case of a failure?
Has the user the full right to replace a faulty network interface?
Has the user the full right to change his own ISP (hence changing the IP address and or DNS domain)?

If the answers to these question are { NO, YES, YES, YES, YES }, then software developers should start considering that:

1) Computer are not their users: I can have a single computer hosting hundredth of user contemporary active. Each of these user may have his own copy of a same software without any of them is aware of the other. So what all those instances will refer to?

2) Users are not the computers: Each leaving persons has the full right to buy use and and destroy whatever number of computer he wants. And no-one will ever ask him for whatever personal ID. I go to the shop, I pay and I go. Who I am, they'll never know. And if I by a software license it' ME who buys, not the computer. I must be able to change whatever piece of hardware (including the whole computer)

3) computers are assembly of hardware each user can (has the full right to... because he payed for them) manipulate without been required to ask anyone whatever permission. Intel removed the CPU-ID feature not just for "privacy reasons" (like to say "oh boy, look how good and sweet I am: I respect your privacy ...), but because the European court retained illegal to have such an identity tracking system, and commissioned a penality that -if multiplied for the number of pieces sold after that sentence- will have resulted result in a 1015 euro.

That said, the problem of "identify the computer" is malposed an badly defined, and cannot have a consistent solution without running into a problem itself, or causing problem to its users.
Is what -in computer science- is defined as "not MT decidable problem".
There is nothing that can be done, so just leave without it.
And don't try to find dirty workaround. Dirty workaround will make your user's home dirty. As they will understand it, you will be doomed away.

I'm sorry to anyone who may feel offended by this, but try to understand at least one in your life how many users feel offended every time, after changing a piece of iron, have to ask to dozens of software vendor to renew a license, reinstall a software, reconfigure keys end so on. It is a completely unfair behavior.

2 bugs found.
> recompile ...
65534 bugs found.
D'Oh! | :doh:


AnswerRe: The never ending story Pin
Perfect.Beat.MC24-Jan-12 11:15
Perfect.Beat.MC24-Jan-12 11:15 
AnswerMessage Closed Pin
24-Jan-12 11:24
professionalMichael Haephrati24-Jan-12 11:24 
GeneralRe: The never ending story Pin
Emilio Garavaglia24-Jan-12 20:18
Emilio Garavaglia24-Jan-12 20:18 
GeneralRe: The never ending story Pin
Matan joice24-Jan-12 20:25
Matan joice24-Jan-12 20:25 
AnswerRe: The never ending story Pin
LeslieM15-Feb-12 12:39
LeslieM15-Feb-12 12:39 
GeneralRe: The never ending story Pin
Emilio Garavaglia16-Feb-12 7:13
Emilio Garavaglia16-Feb-12 7:13 
GeneralRe: The never ending story Pin
LeslieM20-Feb-12 14:47
LeslieM20-Feb-12 14:47 
GeneralRe: The never ending story Pin
Emilio Garavaglia21-Feb-12 10:34
Emilio Garavaglia21-Feb-12 10:34 

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.