Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the motherboard's serial number

I want to bind a program to a specific computer, and for that I want to use the serial number of the motherboard as unique identifier.

Although I could find some examples for C# and Java, I couldn't find anything reliable for C++ (I read WMI can fail depending on the hardware), but surely there's a way to do this in C++ too?

Edit : What I want is, in other words, like a simple and rudimentary licensing system. To make it more clear, here's how it would look like :

#define USER_SERIAL 123456789

double GetMotherBoardSerialNumber();
// ...

double currentSerial = GetMotherBoardSerialNumber();

if(currentSerial != USER_SERIAL) {
    exit 1;
}

It is obviously not perfect, but I don't have any server atm to set up an account system so this could be a temporary solution.

like image 647
Angry Cub Avatar asked Apr 18 '17 13:04

Angry Cub


People also ask

Where do I find my CPU serial number?

The batch number (FPO) is located on the top of the processor. The partial serial number (partial ATPO) is located on the outside edge of the processor. The partial serial number contains the last three to five digits from the full serial number for the processor.

Where can I find the serial number on my Asus laptop?

The serial number is printed directly below the barcode. The label can be found on the side of chassis or the top of the chassis cover.

How do I find my motherboard model number Windows 10?

In Windows 10 you can access this menu by going to Start, typing "System Information" and running the application. Alternatively, hit the Windows key + R to open the Run window, then type "msinfo32" and hit Enter.


2 Answers

If you want real serial numbers I recommended parsing the SMBIOS table.

The first time I dived into getting reliable real hardware id's I ended up reading the SMBIOS directly from mapped Physical Memory (Windows XP). I had tried other approaches that many recommend before this but some were very unreliable and in deployment it was noted that there were duplicates across clients with some of the other methods. How could 20+ people have identical serials? It made no sense and seemed like OEM's had set fields.

From Windows Vista onwards the correct method to retrieve the table is through GetSystemFirmwareTable. This is because it is no longer possible to map Physical Memory on Windows Vista from user-mode (XP64 & Server 2003 were the same too)

GetSystemFirmwareTable can be used to get the SMBIOS data which you can then parse according to the SMBIOS spec. There's a fair amount of data in the table so generating a unique identifier shouldn't be too difficult. IIRC you generally even get serials for DRAM etc...

I would also recommend testing this thoroughly and having a backup plan if the call fails. There are instances where it just fails and having a good idea of the environment that causes failures will save you a lot of time. If my memory serves me right in the Vista days I had issues with UAC and elevated privileges, however MS may have have changed that since then!

like image 180
djgandy Avatar answered Oct 22 '22 09:10

djgandy


You can look at this registry key: [HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\BIOS]. You will see following:

"BiosMajorRelease"
"BiosMinorRelease"
"ECFirmwareMajorRelease"
"ECFirmwareMinorRelease"
"BaseBoardManufacturer"
"BaseBoardProduct"
"BaseBoardVersion"
"BIOSReleaseDate"
"BIOSVendor"
"BIOSVersion"
"SystemFamily"
"SystemManufacturer"
"SystemProductName"
"SystemSKU"
"SystemVersion"

If this doesn't satisfy you, you can still use GetSystemInfo function. I think this use of motherboard information wouldn't help you as unique id. If you want to get unique computer identifier, use GUID or something. To create GUID you need to just:

GUID gidReference;
HRESULT hCreateGuid = CoCreateGuid( &gidReference );
like image 29
Kamila Szewczyk Avatar answered Oct 22 '22 08:10

Kamila Szewczyk