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.