C# How do you get the operating system architecture (x86 or x64)?

20,313

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"));
Share:
20,313
xZerox
Author by

xZerox

Updated on September 04, 2020

Comments

  • xZerox
    xZerox over 3 years

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

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