0

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

How do you know if the operating system is x64 or x86 from a c# .net 2.0 windows applicaiton?

Also the applicaiton is 32bit.

Thanks

Community
  • 1
  • 1
Jonathan D
  • 1,364
  • 2
  • 12
  • 30

1 Answers1

1

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"));

EDIT:

Thanks to Hans Passant for pointing out the error in using the PROCESSOR_ARCHITECTURE variable.

Community
  • 1
  • 1
djdd87
  • 67,346
  • 27
  • 156
  • 195
  • Have you actually tried this? Wow64 is not that easily defeated, emulation covers every corner. Except IsWow64Process and GetNativeSystemInfo. – Hans Passant Sep 03 '10 at 12:27
  • @Hans Passant - Copied from a production system. Should I be worried? – djdd87 Sep 03 '10 at 12:37
  • @Hans Passant - Was a serious question actually. I thought it pulled the value from 'HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE'? How can that be wrong? – djdd87 Sep 03 '10 at 12:41
  • Registry virtualization is also taken care of by Wow64. – Hans Passant Sep 03 '10 at 12:53
  • @Hans Passant - Update the answer. Hopefully that's better. – djdd87 Sep 03 '10 at 13:00
  • Yes, better, I know that one normally exists. What I'm not so sure about is that it is *guaranteed* to exist. Not close to an x64 machine right now to check, but avoid relying on registry keys that initialize the session. If the key is actually in the registry, rather than emulated by Wow64, it might not be there some day on some machine. The linked thread is a reliable way. – Hans Passant Sep 03 '10 at 13:08