Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:winreg模块:Windows 7:None无效HKEY错误_Python_Winreg - Fatal编程技术网

Python:winreg模块:Windows 7:None无效HKEY错误

Python:winreg模块:Windows 7:None无效HKEY错误,python,winreg,Python,Winreg,我在读取windows 7 winth winreg模块的注册表值时遇到问题。是否有指针来解决此问题 代码: try: ParentKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall") i = 0 while 1: name, value, type = _winreg.EnumValue(Par

我在读取windows 7 winth winreg模块的注册表值时遇到问题。是否有指针来解决此问题

代码:

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 += 1

except 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: ' )
输出:

[Error 259] No more data is available
Traceback (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**
[Error 259]没有更多可用数据
回溯(最近一次呼叫最后一次):
文件“C:\Users\Test\workspace\Pythontests\src\Test.py”,第24行,在
temp=\u winreg.queryValuex(ParentKey,'DisplayName')
TypeError:None在此上下文中不是有效的HKEY
**强文本**
此行:

ParentKey = _winreg.DisableReflectionKey(ParentKey)
将返回
None
。函数
DisableReflectionKey
未记录为返回任何内容(成功或失败由是否引发异常来指示)。这种不返回任何内容的函数隐式返回
None
。由于您将返回值绑定到
ParentKey
,因此该变量从此点起将保存
None

所以,当然接下来的电话

_winreg.QueryValueEx(ParentKey, 'DisplayName')
将失败,因为
QueryValueEx
需要定义的键(而不是
None
)才能工作