C# 如何判断系统是32位还是64位


public static int GetOSBit()
{

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 Int32.Parse(addressWidth);
}
catch (Exception ex)
{
return 32;
}

需要引用System.Management,该方法在以Guest用户登录的情况下抛出异常:


或者用以下方法

[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)] 
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWow64Process([In] IntPtr hProcess, [Out] out bool lpSystemInfo);


private static bool Is64Bit()

{

bool retVal;

IsWow64Process( Process.GetCurrentProcess().Handle, out retVal);

return retVal;

}

需要引用System.Diagnostics

参考http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/24792cdc-2d8e-454b-9c68-31a19892ca53/


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM