C#获取操作系统是32位或64位的代码
注意需添加引用System.Management) public static 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) { Console.WriteLine(ex.ToString()); return String.Empty; } }