[Tutor] Recursive functions and the windows registry

Todd Dahl lucidmonk at gmail.com
Thu Nov 16 17:49:55 CET 2006


I have been fighting with this for a couple of days and am getting
frustrated with it. I am trying to figure out a way to walk through the
windows registry and to capture all nodes under the HKEY_CLASSES_ROOT\CLSID
key and then put it into a list.



I have been trying to do it with a recursive function but am having no luck
with it. I am really hoping that it's because I am new to Python and not
because I am doing something stupid but it would not be the first time I
missed something obvious.



This script is a subset of the larger script that I am working on.  Any help
or feedback would be great. I'm getting to the end of my rope.



By the way I don't understand why it seems to work inside the
ListRegistryKeys function but it doesn't pass all the information back to
the parseRegistry function.



-Todd

====


#!/usr/bin/env python

import _winreg # _winreg module allows you to work with the windows registry

def ListRegistryKeys(path):
    # if its empty do nothing
    if not path: return

    key=_winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, path)

    i=0
    name = []

    try:
        while 1:
            name.append(path + "\\" + _winreg.EnumKey(key, i))
            print name[-1]
            i += 1
    except WindowsError:
        pass

    _winreg.CloseKey( key)


    for item in name:
        ListRegistryKeys(item)

    return name


def parseRegistry():
    guidlist = ListRegistryKeys("CLSID")

    for item in guidlist:
        print "parseRegistry: ", item

def main():
    parseRegistry()

if __name__=="__main__":
    main()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061116/469c8294/attachment.html 


More information about the Tutor mailing list