I want to get the same hardware id in windows forms application that i get when i use UnityEngine.SystemInfo.deviceUniqueIdentifier
in my game.
How can I get the same hardware id?
I know I'm late but Unity's SystemInfo::deviceUniqueIdentifier is built like this:
Requires: using System.Management;
in System.Management.dll
(.NET Framework)
private string GetDeviceUniqueIdentifier() {
string ret = string.Empty;
string concatStr = string.Empty;
try {
using ManagementObjectSearcher searcherBb = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard");
foreach (var obj in searcherBb.Get()) {
concatStr += (string)obj.Properties["SerialNumber"].Value ?? string.Empty;
}
using ManagementObjectSearcher searcherBios = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS");
foreach (var obj in searcherBios.Get()) {
concatStr += (string)obj.Properties["SerialNumber"].Value ?? string.Empty;
}
using ManagementObjectSearcher searcherOs = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");
foreach (var obj in searcherOs.Get()) {
concatStr += (string)obj.Properties["SerialNumber"].Value ?? string.Empty;
}
using var sha1 = SHA1.Create();
ret = string.Join("", sha1.ComputeHash(Encoding.UTF8.GetBytes(concatStr)).Select(b => b.ToString("x2")));
} catch (Exception e) {
Console.WriteLine(e.ToString());
}
return ret;
}
I reverse engineered the Unity Editor to find out what it actually queries in the WMI. This is obviously the Windows implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With