Unable to access registry under HKLM/SOFTWARE on a 64 bit platform

1.4k views Asked by At

I was trying to access a custom registry on Win 7 64 bit machine, but every time I try to do that it throws an error saying that

WindowsError: [Error2] The system cannot find the file specified

The registry that I was trying to access is:

HKEY_LOCAL_MACHINE\SOFTWARE\test11

I used the following code to access it:

import _winreg
handle_1 = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,r"SOFTWARE\test11")

Also when I try to create registry, like this:

handle_1 = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE,r"SOFTWARE\test11")

It creates the key in the following location:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\test11

I don't understand why it doesn't create it like this

HKEY_LOCAL_MACHINE\SOFTWARE\test11

3

There are 3 answers

2
Abhinav Bhardwaj On BEST ANSWER

This should work :

import _winreg

        a = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\test', 0, (_winreg.KEY_WOW64_64KEY + _winreg.KEY_ALL_ACCESS))
1
vks On
import _winreg as registry
key = registry.OpenKey(registry.HKEY_LOCAL_MACHINE,r"SOFTWARE\test11",0, registry.KEY_ALL_ACCESS)

for opening you can try this.For creating use

handle_1 = registry.CreateKeyEx(_winreg.HKEY_LOCAL_MACHINE,r"SOFTWARE\test11")
0
Umang Agrawal On

To create a registry key like:

HKEY_LOCAL_MACHINE\SOFTWARE\test11

Use following code:

import _winreg

    a = _winreg.CreateKeyEx(_winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\test', 0, (_winreg.KEY_WOW64_64KEY + _winreg.KEY_ALL_ACCESS))