Reputation: 26694
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
Is there a way to determine if a Windows XP computer has a processor that supports 64bit?
Upvotes: 2
Views: 1157
Reputation: 40838
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.
Upvotes: 1
Reputation: 23731
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();
Upvotes: 2
Reputation: 28272
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
Upvotes: 1