5

Possible Duplicate:
How to detect Windows 64 bit platform with .net?

How can I retrieve the operating system architecture (x86 or x64) with .NET 2.0?

I have not found any good method to get the OS architecture on Google. What I found was how to tell whether the process is 32-bit or 64-bit.

If there isn't anyway to find out in .NET 2.0 please tell me. :)

Community
  • 1
  • 1
xZerox
  • 331
  • 4
  • 7
  • 21

1 Answers1

13

Not the accepted answer in the duplicate question, but this is how I'd do it:

Use GetEnvironmentVariable to look for the PROCESSOR_ARCHITEW6432 variable. If it doesn't exist, you must be running 32bit:

bool is64bit = !string.IsNullOrEmpty(
    Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"));
djdd87
  • 67,346
  • 27
  • 156
  • 195
  • 3
    This seems dramatically simpler than the accepted answer in the dup. – Kirk Woll Sep 03 '10 at 20:02
  • Apparently this is set for WOW64 processes (i.e. 32-bit code running on 64-bit OS). Seems like a kind of flaky thing to check. What's to stop me from setting that environment variable, just for kicks, or just because I like giving your code a hard time? – asveikau Sep 03 '10 at 20:05
  • @asveikau - Nothing at all. It's a simpler piece of code, but like you said, not 100% reliable. – djdd87 Sep 03 '10 at 20:08