有以下幾種方法:
方法壹:
對於C#來說,調用WMI是壹種簡單易行的方式。我們可以用Win32_Processor類裏面的AddressWidth屬性來表示系統的位寬。AddressWidth的值受CPU和操作系統的雙重影響。
具體的值如下面的表格所示:
可以用下面的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;
}
方法二:
bool type;
type = Environment.Is64BitOperatingSystem;
Console.WriteLine(type);
如返回值為True則表示是有,如返回值為False則表示為無。
方法三:
命名空間是System;
前題是程序需要采用any/CPU的方式進行編輯;
if (IntPtr.Size == 8)
{
?//64 bit
}
else if (IntPtr.Size == 4)
{
?//32 bit
}
else
{
?//...NotSupport
}