当前位置: 编程技术>.net/c#/asp.net
c#判断操作系统位数实例代码
来源: 互联网 发布时间:2014-08-30
本文导语: 在.net 4.5中,判断操作系统有直接可以利用的属性了。 例如: Environment.Is64BitProcess 属性.NET Framework 4.5 确定当前进程是否为 64 位进程。 如果是用的.net 4.5以前的,同样也可以用以下的方法来实现判断系统位数。 代码...
在.net 4.5中,判断操作系统有直接可以利用的属性了。
例如:
Environment.Is64BitProcess 属性.NET Framework 4.5
确定当前进程是否为 64 位进程。
如果是用的.net 4.5以前的,同样也可以用以下的方法来实现判断系统位数。
代码:
代码示例:
//判断操作系统位数
//by www.
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;
}
}
//by www.
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;
}
}