您的位置:首页 > 编程语言 > C#

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

2014-06-20 17:59 686 查看
原文地址:http://www.cnblogs.com/tom-tong/archive/2012/03/12/2392173.html

方法一

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: