I'm working on an application that should be able to run 1 of 2 scripts, depending on whether or not the OS running the app is x64 or x86.
Searched around and I came across this thread: How to detect Windows 64-bit platform with .NET?
But apparently my boss is afraid the top answer might not work on all OS' our users will be running (XP/Vista/7). He recommended this code sample:
private void GetCpuDetails(out string cpuType)
{
cpuType = "...";
try
{
using (RegistryKey regKey = Registry.LocalMachine)
{
using (RegistryKey subRegKey = regKey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"))
{
if (subRegKey.GetValue("ProcessorNameString") != null)
{
cpuType = subRegKey.GetValue("ProcessorNameString").ToString();
}
subRegKey.Close();
}
regKey.Close();
}
}
catch
{
cpuType = "...";
}
}
But I don't understand how you could possibly determine the OS version from the CPU. This seems to be exactly the same conundrum as using PROCESSOR_ARCHITECTURE in that it you'd get 64 or 32 bit based on the CPU, not the OS.