2

I want to detect the capabilities op CPU's (especially if it is an 32/64 bit CPU)

The machines are running on a 32-bit OS (WinXP) and I want to detect if these machine are capable to get a 64 bit OS installed.

(BTW: At this point I know how to detect the number of cores...)

Martin Mulder
  • 12,642
  • 3
  • 25
  • 54
  • Maybe this [question](http://stackoverflow.com/questions/2017409/right-way-to-detect-cpu-architecture) can help you to detect CPU architecture. – ahawkthomas May 04 '13 at 10:02
  • Take a look [here][1] and [here][2], they are already answered [1]: http://stackoverflow.com/questions/1542213/how-to-find-the-number-of-cpu-cores-via-net-c [2]: http://stackoverflow.com/questions/1817268/how-can-i-determine-programmatically-whether-on-multi-core-hyperthreading-or-mu – Solaflex May 04 '13 at 10:02
  • @ahawkthomas: I think that answers says something about the currently installed OS, not the CPU itself. – Martin Mulder May 04 '13 at 10:05
  • @Solaflex: I already know how tot detect #cores. – Martin Mulder May 04 '13 at 10:07
  • Sorry Martin Mulder, you are right. Maybe this [WMI solution](http://stackoverflow.com/questions/689228/how-to-know-my-processor-is-32-or-64-bits-in-c) will help? It is based on [Win32_Processor class](http://msdn.microsoft.com/en-us/library/aa394373%28VS.85%29.aspx). – ahawkthomas May 04 '13 at 10:20

2 Answers2

2

You can use WMI to get more details about each CPU, the following properties are available in the Win32_Processor class

You can Use the following code to get the value of each property :

ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor");
ManagementObjectCollection cpus = searcher.Get()
foreach (ManagementObject queryObj in cpus)
{
    Console.WriteLine("AddressWidth : {0}", queryObj["AddressWidth"]); //On a 32-bit operating system, the value is 32 and on a 64-bit operating system it is 64.
    Console.WriteLine("DataWidth: {0}", queryObj["DataWidth"]); //On a 32-bit processor, the value is 32 and on a 64-bit processor it is 64
    Console.WriteLine("Architecture: {0}", queryObj["Architecture"]); //Processor architecture used by the platform
}

I'm not sure if the AddressWidth is the correct property that you need to determine if the CPU is capable with 64 bit OS or not

Amer Sawan
  • 2,126
  • 1
  • 22
  • 40
  • Well... that "bit" part is the one that I am bothering with... As I mentioned: I know how to find the #cores. – Martin Mulder May 04 '13 at 10:20
  • as I told you, you may use the `AddressWidth` property to get whether if the CPU can support 64-bit OS or not, sorry I added `NumberOfCores` as example in my code, I just edited it to write the `AddressWidth` – Amer Sawan May 04 '13 at 10:31
  • The `AddressWidth` represent the operating system architecture, but you can use the `DataWidth` property to get the CPU architecture, check the [MSDN documentation](http://msdn.microsoft.com/en-us/library/windows/desktop/aa394373%28v=vs.85%29.aspx) – Amer Sawan May 04 '13 at 10:42
0

Or if you want to play around with all WMI Classes you could use the WMI Code Creator

I've used it before and it helped me a lot.

DeMama
  • 1,134
  • 3
  • 13
  • 32