views:

267

answers:

3

I'm looking for a very simple way of determining if the version of Windows the customer is using is 32bit or 64bit. I know there are ways using .NEt but I'm looking to avoid them. I simply want to use something similar the below pseudo code and want to know if this method can be reliable.

If Registry Key exists (HKEY_LOCAL_MACHINE\Software\WOW6432Node)
   Then Assume 64bit
else
   Assume 32bit

Thanks!

EDIT: To be more specific, I know there a several different ways to accomplish the goal of finding out if the OS is 32 or 64bit. But I want to know if the above alone method would be reliable.

+1  A: 

You can check the environment variable PROCESSOR_ARCHITECTURE. If it is AMD64 then you are on a 64 bit OS, but this is not safe (after reading comments)

But to be safe, you can call an Win32 API, IsWow64Process as mentioned in this blog post from Raymond Chen.

Arve
...unless the script is running in c:\windows\syswow64\cmd.exe, where is defined as *PROCESSOR_ARCHITECTURE=x86* and there's a separate *PROCESSOR_ARCHITEW6432=AMD64*
Franci Penov
+1  A: 

Why not check for the existence of the folder C:\Program Files (x86)? This will assure you that it's a 64bit OS.

aefxx
...unless some program created it as part of its install, even though it installed on a 32-bit machine. :-)
Franci Penov
very unlikely but possible ^^
aefxx
... or you are running on a localized version of windows
erikkallen
+4  A: 

I assume you are running in a 32-bit process (otherwise you would already know the answer). The solution to your problem is either IsWow64Process or GetNativeSystemInfo.

Luke