JimDel
JimDel

Reputation: 4359

Windows 32 or 64 bit using HKEY_LOCAL_MACHINE\Software\WOW6432 Node

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.

Upvotes: 1

Views: 3313

Answers (4)

rishabhr0y
rishabhr0y

Reputation: 868

i hope this can solve the problem i tried it on my windows 8.1 64 bit and it returns the value AMD64 for me

import _winreg
def get_registry_value(key, subkey, value):

  key = getattr(_winreg, key)
  handle = _winreg.OpenKey(key, subkey )
  (value, type) = _winreg.QueryValueEx(handle, value)
  return value

windowsbit = get_registry_value(
"HKEY_LOCAL_MACHINE",
"SYSTEM\\CurrentControlSet\Control\\Session Manager\\Environment",
"PROCESSOR_ARCHITECTURE")
print windowsbit

just run this code if you are working on 64 bit windows machine this will print AMD64

or if you are working on 32 bit it will print AMD32

i hope this code can help to solve this problem fully

Upvotes: 0

Luke
Luke

Reputation: 11421

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.

Upvotes: 5

Arve
Arve

Reputation: 7506

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.

Upvotes: 0

aefxx
aefxx

Reputation: 25269

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

Upvotes: 0

Related Questions