Python: WinReg Item Module: Windows 7: No Invalid HKEY error
Python winreg
I encountered a problem while reading the registry value of the Windows 7 winth winreg item module. Any pointers to resolve the code:
try: ParentKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall") i = 0 while 1: name, value, type = _winreg.EnumValue(ParentKey, i) print repr(name), i += 1except Exception as e: print(Exception(e))ParentKey =_winreg.DisableReflectionKey(ParentKey) temp = _winreg.QueryValueEx(ParentKey, ‘DisplayName‘)temp1 = _winreg.QueryValueEx(ParentKey, ‘DisplayVersion‘)temp2 = _winreg.QueryValueEx(ParentKey, ‘Publisher‘)temp3 = _winreg.QueryValueEx(ParentKey, ‘InstallLocation‘)display = str(temp[0])display_ver=str(temp1[0])display_p=str(temp2[0])display_loc=str(temp3)print (‘Display Name: ‘ + display + ‘\nDisplay version: ‘ + display_ver + ‘\nVendor/Publisher: ‘ + display_p +‘\nRegkey: ‘ + display_loc +‘\nInstall Location: ‘ )
Output:
[Error 259] No more data is availableTraceback (most recent call last): File "C:\Users\Test\workspace\Pythontests\src\test.py", line 24, in <module> temp = _winreg.QueryValueEx(ParentKey, ‘DisplayName‘)TypeError: None is not a valid HKEY in this context**strong text**
This address: codego.net/8999004/
--------------------------------------------------------------------------------------------------------------- ----------
1. This line:
ParentKey = _winreg.DisableReflectionKey(ParentKey)
will return None
. The function DisableReflectionKey
is not to return anything (or the failure is represented by whether an exception was raised). Such a return function does not return any None
implicit. Since you bind the return value ParentKey
, this variable will be held None
from this point on. So, of course, subsequent calls,
_winreg.QueryValueEx(ParentKey, ‘DisplayName‘)
The QueryValueEx
custom key (not) is required to work because it will fail None
.
This article title: Python: WinReg Item Module: Windows 7: No Invalid HKEY error
This address: codego.net/8999004/
Go to Python: WinReg Item Module: Windows 7: No Invalid HKEY error