在.net 4.5中,判断操作系统有直接可以利用的属性了。
例如:
Environment.Is64BitProcess 属性.NET Framework 4.5
确定当前进程是否为 64 位进程。
如果是用的.net 4.5以前的,同样也可以用以下的方法来实现判断系统位数。
代码:
复制代码 代码示例:
//判断操作系统位数
//by www.jb200.com
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;
}
}