C # Determines whether the system is 64-bit or 32-bit supported. net4.0 Previous Versions

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.