C#斷定體系是32位照樣64位的辦法。本站提示廣大學習愛好者:(C#斷定體系是32位照樣64位的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#斷定體系是32位照樣64位的辦法正文
本文實例講述了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
願望本文所述對年夜家的C#法式設計有所贊助。