Go to Python: WinReg Item Module: Windows 7: No Invalid HKEY error

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.