EnumKey vs EnumValue

Hughes, Chad O chad.hughes at pnl.gov
Mon Jun 6 18:47:03 EDT 2005


EnumKey enumerates subkeys which are equivalent to the folders in
regedit.  EnumValue enumerates values only. The reason your script is
not printing anything must be due to the fact that you are passing in a
registry path that contains only subkeys and no values.  As I mentioned
before, the folders are the subkeys, but the values are the name, type,
data tuple in a given key.  Some loosely call the values keys, but
technically, the keys are the folders and the values are the names.  The
names can be set to a specific data item.  Hence the data column in
regedit.  The type is obviously the data type of the data that is
associated with a given value (name). 

So, to summarize,  keys are the folders that hold values that are set to
data of a specific type.  Keys are equivalent to the path, values are
equivalent to the name in regedit.  That value is assigned a date item
of a specific type.  This can get confusing because people commonly
referred to the values as keys when keys are actually the folders.

-----Original Message-----
From: python-list-bounces+chad.hughes=pnl.gov at python.org
[mailto:python-list-bounces+chad.hughes=pnl.gov at python.org] On Behalf Of
Pykid
Sent: Monday, June 06, 2005 1:07 PM
To: python-list at python.org
Subject: EnumKey vs EnumValue


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."

-- 
http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list