码迷,mamicode.com
首页 > 编程语言 > 详细

转 Python的:WinReg项模块:Windows 7中:无无效HKEY错误

时间:2016-12-22 15:01:44      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:machine   模块   自定义   test   workspace   sts   module   异常   绑定   

Python的:WinReg项模块:Windows 7中:无无效HKEY错误

 

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(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**


本文地址 :CodeGo.net/8999004/ 
------------------------------------------------------------------------------------------------------------------------- 
1.这行:

ParentKey = _winreg.DisableReflectionKey(ParentKey)

将返回None。该函数DisableReflectionKey是不为返回任何东西(或失败是由一个异常是否被升高表示)。这样一个不返回任何回报函数Noneimplicit。既然你绑定返回值ParentKey,这个变量将持有None从这一点上。 所以,当然后续呼叫,

_winreg.QueryValueEx(ParentKey, ‘DisplayName‘)

因为将失败QueryValueEx需要自定义键(不None)工作。
本文标题 :Python的:WinReg项模块:Windows 7中:无无效HKEY错误
本文地址 :CodeGo.net/8999004/ 

转 Python的:WinReg项模块:Windows 7中:无无效HKEY错误

标签:machine   模块   自定义   test   workspace   sts   module   异常   绑定   

原文地址:http://www.cnblogs.com/chengxuyuan326260/p/6210780.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!