Help! Need suggestion !

SunitJoshi SunitJoshi at email.msn.com
Sun May 30 01:44:48 EDT 1999


Hi All
    I'm trying to recurse through registry keys and I'm able to get the key
values, however I can't seem to record the key path, eg: if it's under
HKEY_LOCAL_MACHINE\SOFTWARE\\Microsoft\Visual Basic\6.0\External Tools, I
can print the values under this key like HTML Editor=C:\windows\notepad.exe.
but I have trouble recording the whole path.
    I guess I'm missing something here, if someone could please point it out
I would really appreciate it.

Code follows:

import win32ui, win32api
import win32con

commonString = "SOFTWARE\\Microsoft"

def
makeRootKey(Key=win32con.HKEY_LCAL_MACHINE,keyString="SOFTWARE\\Microsoft\\"
, mode=win32con.KEY_READ):
    return win32api.RegOpenKeyEx(key, keyString, 0, mode)


def dumpKeys():
 key = makeRootKey() # This just returns the key to
                                        #
HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft
 searchKeys(key, "SOFTWARE\\Miscrosoft")


def searchKeys(Instance, object):
    global commonString
    key = makeRootKey(Key=Instance, keyString=object)
    if not key==None:
        dumpValues(key, object)

    keys = []
    keyNo=0

    while 1:
      try:
       keyName = win32api.RegEnumKey(key, keyNo)
       keys.append(keyName)
       keyNo = keyNo + 1
     except win32api.error:
       if len(keys) == 0:
        return
     else:
        break

    savedKeys = keys[:]
      for name in savedKeys:
        subKey = name
        commonString = commonString + "\\" + subKey
        searchKey(key,subKey)

    win32api.RegCloseKey(key)


def dumpValues(key, subKey):
    global commonString
     keyNo=0
     while 1:
         try:
            (Name,Data,Type) = win32api.RegEnumValue(key, keyNo)
            print "Key>%s\n" %commonString
            print "-" * (len("Key>") + len(commonString))

            keyNo = keyNo + 1
        except win32api.error:
            print "\n"
            return








More information about the Python-list mailing list