I am trying to get the CPU serial number but I cannot do it. I can get board and harddisk but not cpu.
here is my code below. what am I doing wrong?
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
{
}
}
Try this one
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;
}
Code Extracted from here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.