Python winreg looping through sub-keys

前端 未结 6 1382
悲哀的现实
悲哀的现实 2021-01-12 05:16

I\'m able to successfully retrieve the 5 sub-keys from my windows 7 machine registry hive \"HKEY_LOCAL_MACHINE\" with the code below.

from _winreg import *

         


        
6条回答
  •  走了就别回头了
    2021-01-12 05:35

    Does something like this work?

    import _winreg
    
    def subkeys(key):
        i = 0
        while True:
            try:
                subkey = _winreg.EnumKey(key, i)
                yield subkey
                i+=1
            except WindowsError:
                break
    
    def traverse_registry_tree(key=_winreg.HKEY_LOCAL_MACHINE, tabs=0):
        for k in subkeys(key):
            print '\t'*tabs + str(k)
            traverse_registry_tree(k, tabs+1)
    

提交回复
热议问题