c# 获取machineguid_获取Windows序列号(以前是:从注册表中获取MachineGuid)
时间: 2024-01-16 09:03:16 浏览: 344
C++读取注册表中的MachineGuid
您可以使用以下代码获取Windows序列号(MachineGuid):
```csharp
using System;
using System.Management;
public static string GetMachineGuid()
{
string machineGuid = string.Empty;
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT MachineGuid FROM Win32_ComputerSystemProduct");
foreach (ManagementObject mo in searcher.Get())
{
machineGuid = mo["MachineGuid"].ToString();
break;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return machineGuid;
}
```
这段代码使用WMI查询获取Windows系统的MachineGuid,它不需要访问注册表。
阅读全文