The following code fragment is the C # Check system is 32-bit or 64-bit, the need for friends can be directly tested.
The code is as follows |
Copy Code |
Using System; Using System.Collections.Generic; Using System.Text; Using System.Management; public class Check64or32system { <summary> Check the system for 32-bit or 64-bit </summary> <returns>0 run error; 32 indicates 32-bit system; 64 indicates 64-bit operating system </returns> public static int Distinguish64or32system () { Try { Get Addresswidth value 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 (); String retVal = String. Empty; foreach (ManagementObject mobject in mobjectcollection) { RetVal = mobject["Addresswidth"]. ToString (); } Judging by value, you cannot return the resulting value directly, 32 bits return "32", 64 bits will have two values due to CPU, "N/a" or "64" if (RetVal = = "32") { return 32; } Else { return 64; } } Catch { return 0; } } } |