c# - 如何获得与 UnityEngine.SystemInfo.deviceUniqueIdentifier 中相同的硬件 ID?
问题描述
我想在 Windows 窗体应用程序中获得UnityEngine.SystemInfo.deviceUniqueIdentifier
与我在游戏中使用时获得的相同的硬件 ID。
如何获得相同的硬件 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.
推荐阅读
- node.js - 从 cron/shellJS 重新启动 pm2 - bcrypt 版本错误
- python - subprocess.check_ouput 吐出错误第 356 行和第 438 行
- db2 - db2iupdt 错误:指定的实例“instance_name”不存在
- mongodb - Mongo $meta textScore 未在查询结果中返回
- html - 为什么我的固定元素会移到整个屏幕的右侧而不是其父元素的右侧?
- apache - 拦截主机服务器上的 HTTP 请求和响应
- android - Jenkins 有时会在 LEGACY 资源模式下运行 robolecrtic 测试
- go - SublimeText 中的 Gofmt 插件未找到 GOPATH 错误
- python - 指定大小的随机子集的 Numpy 列表
- c++ - 如何安全地将变量的值传递给 C++ 方法,该方法仅将 void* 作为参数?