在.net 4.5中,判断操作系统不用再写方法去判断了,有直接可以利用的属性了哦,如下所示:
Environment.Is64BitProcess 属性.NET Framework 4.5
确定当前进程是否为 64 位进程。
当然如果是用的.net 4.5以前的童鞋也不必担心,同样也可以用以下的方法来实现判断系统位数。
复制代码 代码如下:
private string Distinguish64or32System()
{
try
{
string addressWidth = String.Empty;
ConnectionOptions mConnOption = new ConnectionOptions();
ManagementScope mMs = new ManagementScope("//localhost", mConnOption);
ObjectQuery mQuery = new ObjectQuery("select AddressWidth from Win32_Processor");
ManagementObjectSearcher mSearcher = new ManagementObjectSearcher(mMs, mQuery);
ManagementObjectCollection mObjectCollection = mSearcher.Get();
foreach (ManagementObject mObject in mObjectCollection)
{
addressWidth = mObject["AddressWidth"].ToString();
}
return addressWidth;
}
catch (Exception ex)
{
return String.Empty;
}
}