views:

195

answers:

1

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. :)

+2  A: 

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"));
GenericTypeTea
This seems dramatically simpler than the accepted answer in the dup.
Kirk Woll
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
@asveikau - Nothing at all. It's a simpler piece of code, but like you said, not 100% reliable.
GenericTypeTea