SDKs
...
Tutorials
Best Practices

Hardware ID

12min

Hardware ID is a unique device identifier used to activate a license. It is important value that helps to link a license to a device and avoid transferring licenses to other devices.

This tutorial will help you learn more about device id algorithms provided by the LicenseSpring SDK and choose the optimal device id algorithm for your application.

Prerequisites

  1. Completed the Getting Started Tutorial, including:
    • Initialized LicenseManager (or LicenseHandler) with your configuration using the appropriate settings.
    • Activated a license of any type.
    • Implemented routine local and online checks within the application.

Hardware ID Algorithms

Default Algorithm

  1. Windows: Default device id uses WMI to get Model, Manufacturer, Name, SerialNumber of the motherboard, processor and disc drive. Then it encodes these values to provide a unique string that represents the current device.
  2. Linux:Default device id reads the machine id from the /etc/machine-id file. This file contains the unique machine ID of the local system that is set during installation or boot. If this id is not found, it tries to read the /var/lib/dbus/machine-id file. If it still fails to get the id, it writes a generated UUID.
  3. MacOS: The C++ SDK uses the gethostuuid() system call to get a unique identifier of the device. The .Net SDK gets IOPlatformUUID value.
  4. Swift: Swift SDK uses machine UUID in macOS SDK and UIDevice.current.identifierForVendor in iOS SDK.

Windows Algorithms

C++ SDK

  1. Gen2 algorithm is similar to the default algorithm. It is safer and shorter than default. This algorithm retrieves the Manufacturer and SerialNumber of the motherboard, CPU name and id, and disc model and serial number. This algorithm can be useful for air gap licenses.
  2. WinCSProductId is an alternative algorithm for Windows. It gets the UUID of the Windows machine using Computer System Product Id through WMI.
  3. WinCryptographyId is an algorithm for Windows that doesn't use WMI. It gets Microsoft Cryptography MachineGuid from Windows registry.

.Net SDK

  1. Gen1 includes minor improvements for ID calculation on Windows, on other platforms the same as default.
  2. Gen2 and Gen3 are safer device id algorithms on Windows, on other platforms the same as default. Gen3 is a shorter form that can be useful for air gap licenses.
  3. WinAlternative algorithm tries to get Microsoft Cryptography MachineGuid from Windows registry. If this request fails or .Net Framework version is earlier than 4.0, it tries to get the UUID of the Windows machine using Computer System Product Id.

Cloud Platform Algorithms

  1. CloudPlatformsId is useful when the software runs on Azure, AWS or GCP. It is a good option when the application will be used only on these platforms. If the application can be installed on other platforms as well, the AutoId algorithm should be used.
  2. AutoId uses different approaches depending on your platform. If the application is running on Azure, AWS or GCP, it is the same as CloudPlatformsId, otherwise the same as Default.
  3. AutoIdWinCloud also uses different platform-dependent approaches. If the application is running on Azure, AWS or GCP, it is the same as CloudPlatformsId, otherwise the same as WinCSProductId. This algorithm should only be used on Windows computers.



Hardware ID Usage

Configuration

When you have chosen the algorithm, set it to the ExtendedOptions.

C++
C#
Swift


.NET SDK allows to specify the timeout for cloud platforms id requests. It is useful when AutoId takes too long on a regular machine. This value is specified in milliseconds, the default is 200.

C#


The SDK allows overriding hardware ID. For instance, you can use the MAC address as the hardware ID:

C++
C#


Relink License

The relink license method can be useful when the device algorithm has been changed. Despite the license belongs to the device, local check will throw DeviceNotLicensedException since the device IDs don’t match. In this case you can relink the license to the new id. 

C++
C#


This method checks if the old device id of the license matches any of the IDs generated by different algorithms. When it finds the correct option, it deactivates the license with the old ID and activates it again using the new algorithm. This method throws the same exceptions as a regular license activation.

C++ SDK provides unlinkFromDevice and isLicenseBelongsToThisDevice methods. The first one checks if the license belongs to this device and deactivates it. It may throw the same exceptions as the deactivate method. The isLicenseBelongsToThisDevice method  checks if the license belongs to the provided DeviceIDAlgorithm on this machine.

Recovering WMI

On Windows 11/10 WMI Repository issues can occur. It is good to know how to fix them since most of the device ID algorithms use WMI. Here are a couple of ways to recover WMI service:

  1. To check if the WMI repository is consistent, the open Command Prompt with admin privileges and run winmgmt /verifyrepository. If you don't get a message stating WMI repository is consistent, proceed with the next steps.
  2. In the same admin Command Prompt window, run the three following commands: cd C:\Windows\system32\wbem mofcomp.exe CIMWin32.mof regsvr32 cimwin32.dll
  3. You can also try to recover WMI by running the following command from Command Prompt with admin privileges: winmgmt /resetrepository . For more information, see https://stackoverflow.com/a/71535626 Be informed about the risks of running the command above, for more information see https://techcommunity.microsoft.com/t5/ask-the-performance-team/wmi-repository-corruption-or-not/ba-p/375484