现在的位置: 首页 > 综合 > 正文

判断32位OS,64位OS的方法

2012年09月11日 ⁄ 综合 ⁄ 共 960字 ⁄ 字号 评论关闭

判断系统是否是64位的方法有很多。

对于C#来说,调用WMI是一种简单易行的方式。我们可以用Win32_Processor类里面的AddressWidth属性来表示系统的位宽。AddressWidth的值受CPU和操作系统的双重影响。

具体的值如下面的表格所示:

  32bit OS 64bit OS
32bit CPU AddressWidth = 32 N/A
64bit CPU AddressWidth = 32 AddressWidth = 64

可以用下面的C#代码得到AddressWidth的值
(注意需添加引用System.Management)

public static string Detect3264()
{
             ConnectionOptions oConn
= new ConnectionOptions();
             System.Management.ManagementScope oMs
= new System.Management.ManagementScope("////localhost", oConn);
             System.Management.ObjectQuery oQuery
= new System.Management.ObjectQuery("select AddressWidth from Win32_Processor");
             ManagementObjectSearcher oSearcher
= new ManagementObjectSearcher(oMs, oQuery);
             ManagementObjectCollection oReturnCollection
= oSearcher.Get();
            
string addressWidth = null;

            foreach (ManagementObject oReturn in oReturnCollection)
             {
                 addressWidth
= oReturn["AddressWidth"].ToString();
             }

            return addressWidth;
}

 

抱歉!评论已关闭.