我正在尝试获取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
{
}
}
if (PC.Name == "ProcessorID")
吗? - ThewadsPC.Value
Can returnnull
then you will get an exception. Usevar value = (string)PC.Value
- Andrei Krasutski