【问题标题】:How to detect if CPU is 32 or 64 bit如何检测 CPU 是 32 位还是 64 位
【发布时间】:2013-05-04 09:59:51
【问题描述】:

我想检测 op CPU 的功能(特别是如果它是 32/64 位 CPU)

这些机器在 32 位操作系统 (WinXP) 上运行,我想检测这些机器是否能够安装 64 位操作系统。

(顺便说一句:此时我知道如何检测核心数...)

【问题讨论】:

标签: c# .net cpu 32bit-64bit cpu-cores


【解决方案1】:

您可以使用 WMI 获取有关每个 CPU 的更多详细信息,following properties are available in the Win32_Processor class

您可以使用以下代码获取每个属性的值:

ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor");
ManagementObjectCollection cpus = searcher.Get()
foreach (ManagementObject queryObj in cpus)
{
    Console.WriteLine("AddressWidth : {0}", queryObj["AddressWidth"]); //On a 32-bit operating system, the value is 32 and on a 64-bit operating system it is 64.
    Console.WriteLine("DataWidth: {0}", queryObj["DataWidth"]); //On a 32-bit processor, the value is 32 and on a 64-bit processor it is 64
    Console.WriteLine("Architecture: {0}", queryObj["Architecture"]); //Processor architecture used by the platform
}

我不确定 AddressWidth 是否是您需要确定 CPU 是否支持 64 位操作系统的正确属性

【讨论】:

  • 嗯......那个“位”部分是我所困扰的......正如我所提到的:我知道如何找到#cores。
  • 正如我告诉你的,你可以使用AddressWidth属性来获取CPU是否支持64位操作系统,对不起,我在我的代码中添加了NumberOfCores作为示例,我只是编辑它写AddressWidth
  • AddressWidth代表操作系统架构,但是可以使用DataWidth属性获取CPU架构,查看MSDN documentation
【解决方案2】:

或者,如果您想使用所有 WMI 类,您可以使用 WMI Code Creator

我以前用过,对我帮助很大。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-10
    • 2014-07-04
    • 2015-12-03
    相关资源
    最近更新 更多