遍历值或注册表项。_winreg Python [英] Loop through values or registry key.. _winreg Python

查看:376
本文介绍了遍历值或注册表项。_winreg Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Python模块_winreg遍历Windows注册表项的全部。我有满足我需要的代码,但是它是用于指定注册表项的子项的。

How would I loop through all the values of a Windows Registry Key using the Python module _winreg. I have code that will do what I want, but it is for the subkeys of the specified registry key.

代码在这里:

from _winreg import *
t = OpenKey(HKEY_CURRENT_USER, r"PATH TO KEY", 0, KEY_ALL_ACCESS)

try:
    i = 0
    while True:
        subkey = EnumValue(t, i)
        print subkey
        i += 1
except WindowsError:
    # WindowsError: [Errno 259] No more data is available    
    pass






哦,知道了。但是,如果有人知道另一种方法,我仍然会接受该答案!


Oh, figured it out. But, if anyone knows of another way to do it, I'll still accept that answer!

推荐答案

不应将EnumValue设为帮助

Shouldn't EnumValue be of help here

# list all values for a key
try:
    count = 0
    while 1:
        name, value, type = _winreg.EnumValue(t, count)
        print repr(name),
        count = count + 1
except WindowsError:
    pass

这篇关于遍历值或注册表项。_winreg Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆