2

Currently I am using:

ManagementObjectSearcher searcher = 
                   new ManagementObjectSearcher("Select * FROM WIN32_Processor");
ManagementObjectCollection mObject = searcher.Get();

foreach (ManagementObject obj in mObject)
{
  var architecture = obj.GetPropertyValue("Architecture");
}

architecture = 0

This article shows that 0 means x86

The processor that the computer is running is intel core 2 duo E7500

OS is Windows XP 32 bit

CPU-Z shows

enter image description here

Is there a way to determine if a Windows XP computer has a processor that supports 64bit?

Aducci
  • 26,101
  • 8
  • 63
  • 67
  • http://stackoverflow.com/questions/1478290/net-framework-get-running-processor-architecture , although you may need to pinvoke GetNativeSystemInfo depending on requirement : http://msdn.microsoft.com/en-us/library/windows/desktop/ms724340(v=vs.85).aspx – James Gaunt Oct 31 '12 at 17:56
  • Check this out:- http://stackoverflow.com/questions/12212385/detect-if-the-processor-is-64-bit-under-32-bit-os – Rahul Tripathi Oct 31 '12 at 17:57
  • @JamesGaunt/RahulTripathi - It still returns 32bit – Aducci Oct 31 '12 at 18:03
  • check this out : http://www.pinvoke.net/default.aspx/kernel32/GetSystemInfo.html – Yoav Oct 31 '12 at 18:07
  • Why the downvote? The previous questions do not address my problem – Aducci Oct 31 '12 at 18:09
  • @Yoav - I have tried that, but it still shows 32 bit. I believe the reason is because my OS is 32bit – Aducci Oct 31 '12 at 18:10
  • @Aducci What does the management object return for the Name, DataWidth, AddressWidth, Family, and ProcessorType properties? – Mike Zboray Oct 31 '12 at 18:12
  • These are all cross your fingers jobs. You are hoping the 32 bit driver for the processor bothers to tell windows32 its a 64 bit chip. Don't bet anything you care about on it always working. – Tony Hopkinson Oct 31 '12 at 18:14
  • @mikez - it returns: "Intel Pentium III Xeon processor", 32, 32, 176, 3 – Aducci Oct 31 '12 at 18:16
  • @Aducci, What about the "ConfigManagerErrorCode" property? If that is non-zero it would indicate that there is an error loading the driver. Otherwise, do you have any independent verification of CPU-Z? What does the bios say? – Mike Zboray Oct 31 '12 at 18:29
  • If `Environment.Is64BitOperatingSystem` is `false` and you want to do something as 64 bit aren't you stuck anyway? Or can the user install another OS? – Brad Oct 31 '12 at 20:56

3 Answers3

2

It may not be ideal, but it's relatively straightforward to create a (native) DLL using VC++ or the like and query the processor's features directly. This method could then be PInvoked from your C# application.

The following C++ method would return true when run on a 64 bit capable processor, and false on a 32 bit only processor (whether the OS is 32 or 64 bit):

bool __declspec(naked) IsCPU64BitCapable()
{
    __asm
    {
        // Save EBX since it's affected by CPUID
        push ebx
        // Determine whether the CPU supports retrieving extended feature data
        mov eax, 0x80000000
        cpuid
        cmp eax, 0x80000000
        // No extended data => no 64 bit
        jbe no_extended_data
        // Request extended feature data
        mov eax, 0x80000001
        cpuid
        // Bit 29 of EDX will now indicate whether the CPU is 64 bit capable
        mov eax, edx
        shr eax, 29
        and eax, 1
        jmp extended_data
    no_extended_data:
        xor eax,eax
    extended_data:
        // Restore EBX
        pop ebx
        ret
    }
}

This method can then be used from C# using:

[DllImport("Test64Bit.dll")]
private static extern bool IsCPU64BitCapable();
Iridium
  • 23,323
  • 6
  • 52
  • 74
1

An easy but not foolproof method would be checking the CPU in the registry, should be in HKLM\HARDWARE\DESCRIPTION\CentralProcessor\0.

Something like

var rk = Registry.LocalMachine.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
if (rk.GetValue("Identifier").ToString().IndexOf("64") > 0)
{
   // Is 64 bits
} else {
   // Is 32 bits
}

Not sure if that will be enough for you

Jcl
  • 27,696
  • 5
  • 61
  • 92
  • The registry setting shows `x86 Family 6 Model 23 Stepping 10` – Aducci Oct 31 '12 at 18:11
  • Uhm, that's right, probably because the CPU driver is 32bit. I guess you could extract it from the `FeatureSet` registry key (check for LM, or EM64T), however that key is pretty cryptic (I haven't found specific information about it), and it's there because the driver fills it, so it could actually hide the 64 bit features on a 32 bit driver. Sorry then, not being of much help here :/ – Jcl Oct 31 '12 at 18:28
1

This kb article may describe what you are seeing. The suggested work around is to go the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\ACPI under which there will be a key with the processor's friendly name. You could infer the architecture from whether the friendly name contains Intel64 or x86.

Mike Zboray
  • 39,828
  • 3
  • 90
  • 122