通过Environment 获取 ProcessorCount 属性值
int cpucount=Environment.ProcessorCount
通过 ManagementClass 初始化 win32_processor, 获取 Name ,Caption ,SocketDesignation 等信息
/// <summary>
/// 获取处理器信息
/// </summary>
/// <returns></returns>
public static string GetProcessorInformation()
{
ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();
string info = string.Empty;
foreach (ManagementObject mo in moc)
{
// 处理器型号,说明,插槽类型,时钟频率
string name = (string)mo["Name"];
name = name.Replace("(TM)", "™").Replace("(tm)", "™").Replace("(R)", "®").Replace("(r)", "®").Replace("(C)", "©").Replace("(c)", "©");
name = name.TrimEnd(' ');
info = name + "," + (string)mo["Caption"] + "," + (string)mo["SocketDesignation"] + "插槽";
info += "," + GetCpuSpeedInGHz() + "GHz";
}
return info;
}
获取cpu时钟频率信息
/// <summary>
/// cpu时钟频率
/// </summary>
/// <returns></returns>
public static double? GetCpuSpeedInGHz()
{
double? GHz = null;
using (ManagementClass mc = new ManagementClass("Win32_Processor"))
{
foreach (ManagementObject mo in mc.GetInstances())
{
// CurrentClockSpeed:单位是MHz
GHz = 0.001 * (UInt32)mo.Properties["CurrentClockSpeed"].Value;
break;
}
}
return GHz;
}