/// <summary>
/// 获取机器guid
/// </summary>
/// using System.Management; // 需要添加System.Management的引用
/// <returns></returns>
public static string GetMachineGuid()
{
string location = @"SOFTWARE\Microsoft\Cryptography";
string name = "MachineGuid";
using (var classesRootKey = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64))
{
using (var regKey = classesRootKey.OpenSubKey(location))
{
if (regKey != null)
{
var machineGuid = regKey.GetValue(name);
if (machineGuid != null)
{
return machineGuid.ToString();
}
}
}
}
return null;
}
c#读取64位系统注册表,保证项目的唯一
于 2024-04-28 16:33:19 首次发布
本文提供了一个C#函数,通过Windows注册表获取计算机的机器GUID。该函数使用`System.Management`库和`RegistryKey`类在64位本地机器视图中定位并读取MicrosoftCryptography下的MachineGuid值。
896

被折叠的 条评论
为什么被折叠?



