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()
The following built-in methods are available:
|Includes the operating system version in the device identifier.
|Includes the MAC address in the device identifier.
|Includes the processor ID in the device identifier.
|Includes the motherboard serial number in the device identifier.
|Includes the current user's name in the device identifier.
|Includes the machine name in the device identifier.
|Includes the contents of a file in the device identifier. If the file does not exist, a new file will be created.
|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:
Hopefully you find this library useful, and it helps you avoid hand-rolling your own custom device identifiers!