C # how to determine whether the system is 64-bit or 32-bit

Source: Internet
Author: User

There are many ways to determine whether the system is 64-bit.

For C #, WMI is a simple method. We can use the addresswidth attribute in the win32_processor class to indicate the system bit width. The addresswidth value is affected by the CPU and operating system.

The specific values are shown in the following table:

32bit OS 64bit OS
32bit CPU Addresswidth = 32 N/
64-bit CPU Addresswidth = 32 Addresswidth = 64

You can use the following C #CodeObtains the addresswidth value.
(Note that you need to add reference 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;
}
}

WMI (Windows Management Instrumentation) is used in many ways.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.