Generating a unique identifier for a Windows PC

Using my DeviceId library to generate unique identifiers for Windows PCs.


When developing software for Windows PCs, it is often useful to be able to generate a unique identifier for a given PC. Unfortunately, there is no "standard" way to generate such an identifier, and there are different opinions on how it should be done.

In order to make it easier for .NET developers to build unique identifiers, I have published DeviceId, an open souce C# library that facilitates building custom composite device identifiers using a quick-and-easy fluent interface.

As a quick example, generating a device identifier using the MAC address, processor ID, and motherboard serial number is this simple:

string deviceId = new DeviceIdBuilder()
    .AddMACAddress()
    .AddProcessorId()
    .AddMotherboardSerialNumber()
    .ToString();

The following built-in methods are available:

Method Description
AddOSVersion() Includes the operating system version in the device identifier.
AddMACAddress() Includes the MAC address in the device identifier.
AddProcessorId() Includes the processor ID in the device identifier.
AddMotherboardSerialNumber() Includes the motherboard serial number in the device identifier.
AddUserName() Includes the current user's name in the device identifier.
AddMachineName() Includes the machine name in the device identifier.
AddFileToken(path) Includes the contents of a file in the device identifier. If the file does not exist, a new file will be created.
AddComponent(component) Includes an arbitrary component in the device identifier.

The library is easily extensible, with the AddComponent method facilitating adding an arbitrary value to the device identifier, either by using the general DeviceIdComponent class, or by implementing the IDeviceIdComponent interface.

The library is available on NuGet:

Install-Package DeviceId

Hopefully you find this library useful, and it helps you avoid hand-rolling your own custom device identifiers!


Posted by Matthew King on 31 July 2016
Permission is granted to use all code snippets under CC BY-SA 3.0 (just like StackOverflow), or the MIT license - your choice!