我正在尝试获取CPU序列号,但我不能这样做。我可以获得电路板和硬盘而不是CPU。
这是我的代码如下。我做错了什么?
public static void GetClientComputerInfo()
{
HDDSerial = "0";
BoardSerial = "0";
CPUSerial = "0";
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_DiskDrive");
foreach (ManagementObject share in searcher.Get())
{
foreach (PropertyData PC in share.Properties)
{
if (PC.Name == "SerialNumber")
{
HDDSerial = PC.Value.ToString();
}
if (PC.Name == "SerialNumber")
{
BoardSerial = PC.Value.ToString();
}
if (PC.Name == "ProcessorID")
{
CPUSerial = PC.Value.ToString();
}
}
}
}
catch
{
}
}
答案 0 :(得分:5)
试试这个
string cpuInfo = string.Empty;
ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
cpuInfo = mo.Properties["processorID"].Value.ToString();
break;
}
从here
中提取的代码