There are 2 types of registry. There is a 32-bit registry representation and a 64-bit registry representation. By default, and in most cases, 32-bit applications will see only a 32-bit representation of the registry, and 64-bit applications will see only a 64-bit representation of the registry.
You can access another view using the access flags KEY_WOW64_64KEY or KEY_WOW64_32KEY.
If you use 32-bit python and your key is part of the 64-bit registry, you should use something like this to open your key:
winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\MySoftware\\MyEvent\\IS", access=winreg.KEY_READ | winreg.KEY_WOW64_64KEY)
If you are using 64-bit python, and your key is part of the 32-bit registry, you should use something like this to open your key:
winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\MySoftware\\MyEvent\\IS", access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY)
If you know that the key is always part of the same view, adding the correct KEY_WOW64_* access flag ensures that it works regardless of your python architecture.
In the most general case, if you have a python architecture variable and you donβt know in advance what representation the key will be in, you can try to find the key in your current view and try a different view. It might look something like this:
try: key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\MySoftware\\MyEvent\\IS") except FileNotFoundError: import platform bitness = platform.architecture()[0] if bitness == '32bit': other_view_flag = winreg.KEY_WOW64_64KEY elif bitness == '64bit': other_view_flag = winreg.KEY_WOW64_32KEY try: key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\MySoftware\\MyEvent\\IS", access=winreg.KEY_READ | other_view_flag) except FileNotFoundError: ''' We really could not find the key in both views. '''
For more information, visit Access to an alternate registry view .