Check if your system is a 32-bit or 64-bit C # function

Source: Internet
Author: User

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;
}
}


}

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.