EnumKey vs EnumValue

Pykid mfurmaniuk at gmail.com
Mon Jun 6 16:07:17 EDT 2005


I'm having trouble getting any responses back from the following
snippet, where I am just trying to read some data from the Windows
Registry.  I intend to do a little bit more with this but will work on
that later, but I think I can get more data back from EnumValue, I'd
like to see the differences between them.  I am running Python 2.3 on
XP and can get a response from EnumKey, but EnumValue returns nothing
at all; the key listing even returns 0 keys when it prints out the
status.  But EnumKey returns the right number and even prints out the
keys I expect, I copied some of this from the Cookbook and can't tell
what might be the problem.

  Thanks for any help.

  - M
-------------------------------------

from _winreg import *

findkey = raw_input("What key do you want to look for?  ")

key = "SOFTWARE\\"+findkey
machine = ConnectRegistry(None,HKEY_LOCAL_MACHINE)
regpath = OpenKey(machine,key)

print "Looking for",key

for i in range(25):
    try:
        regEndeca = EnumKey(regpath,i)
        print regEndeca
    except EnvironmentError:
        print "There are", i,"keys under",key
        break
print "That was using EnumKey."

for j in range(25):
    try:
        regstr,value,type = EnumValue(regpath,j)
        print regstr,value,type
    except EnvironmentError:
        print "There are", j,"keys under",key
        break
print "That was using EnumValue."




More information about the Python-list mailing list