Just the other day, I wanted to detect if an application is running on 32 or 64 bit (x86 versus x64) Windows operating system so I could display it in a label control. I thought to myself "ok that should be easy with a registry key or a file version of a system file," but I didn't know a definitive source so off I go to the wild, wild web. A few searches [1, 2, 3] yielded no useful results for doing this programmatically [and yes, I tried Google too ].
So I turned to my brother who has been working with operating system deployments in our data centers for the past 10 years [probably what I should have done in the first place]. Just as I thought, there is a registry key that gives you this information. Since I couldn't find it easily online, I'll add it here.
HKLM\System\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE
Adding this to a .NET C# application is only a few lines of code (using Microsoft.Win32 namespace):
private string GetProcessorArchitecture() { RegistryKey environmentKey = Registry.LocalMachine; // points to HKLM hive environmentKey = environmentKey.OpenSubKey (@"System\CurrentControlSet\Control\Session Manager\Environment", false); string strEnvironment = environmentKey.GetValue("PROCESSOR_ARCHITECTURE").ToString(); return strEnvironment; }
So there you go...how to determine whether the architecture of the operating system is 32-bit or 64-bit.
~tod
Email or RSS 1.0, RSS 2.0 & Atom