C # To determine whether the system is 64-bit or 32-bit reference to a string of code, this code is reproduced from other blog posts in the garden, the introduction of their own projects found unusable, after referencing the corresponding namespace or prompt:
"Could not find type or namespace name" ConnectionOptions "(is missing a using directive or assembly reference?)" ;
In addition to using the use System.Management; It also needs to be referenced in the "references" of the solution to work,
Private stringDistinguish64or32system () {Try{stringAddresswidth = String.Empty; ConnectionOptions mconnoption =NewConnectionOptions (); Managementscope MMs =NewManagementscope ("//localhost", mconnoption); ObjectQuery Mquery =NewObjectQuery ("Select Addresswidth from Win32_Processor"); ManagementObjectSearcher Msearcher =NewManagementObjectSearcher (MMs, mquery); Managementobjectcollection mobjectcollection = Msearcher.get ();foreach(ManagementObject Mobjectinchmobjectcollection) {addresswidth = mobject["Addresswidth"]. ToString (); }returnAddresswidth; }Catch{returnString.Empty; } }
The reference perfectly solves the problem of judging whether the system is 32-bit or 64-bit. This allows different code snippets to be triggered depending on the number of system bits.
C # Determines whether the system is 64-bit or 32-bit supported. net4.0 Previous Versions