c#中如何获得 cpu型号

2024-12-25 01:12:28
推荐回答(2个)
回答1:

internal static string GetCpuInfo()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\CIMV2", "SELECT * FROM Win32_Processor");
foreach (ManagementObject obj2 in searcher.Get())
{
try
{
return (obj2.GetPropertyValue("Name").ToString() + "," + obj2.GetPropertyValue("CurrentClockSpeed").ToString() + " Mhz," + Environment.ProcessorCount.ToString() + " 个处理器");
}
catch
{
continue;
}
}
return "未知";
}

internal static string GetCpuID()
{
ManagementObjectCollection instances = new ManagementClass("Win32_Processor").GetInstances();
foreach (ManagementObject obj2 in instances)
{
return obj2.Properties["ProcessorId"].Value.ToString();
}
return null;
}

回答2:

你直接去百度里面搜一下,一大堆的!或者去博客园里看一下