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 # code to obtain the addresswidth value.
(Note that you need to add reference system. Management)
Public static string detect3264 ()
{
Connectionoptions oconn = new connectionoptions ();
System. Management. managementscope OMS = new system. Management. managementscope ("// localhost", oconn );
System. Management. objectquery oquery = new system. Management. objectquery ("select addresswidth from win32_processor ");
Managementobjectsearcher osearcher = new managementobjectsearcher (OMS, oquery );
Managementobjectcollection oreturncollection = osearcher. Get ();
String addresswidth = NULL;
Foreach (managementobject oreturn in oreturncollection)
{
Addresswidth = oreturn ["addresswidth"]. tostring ();
}
Return addresswidth;
}