EnumKey vs EnumValue

2005-06-06 Thread Pykid
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


Re: EnumKey vs EnumValue

2005-06-07 Thread Pykid
Ok, this was not how I understood it to work earlier when I was going
over this.

I do want to eventually see the values under each key, so I guess if I
want to see what is under each key I need to then reopen it and send
that value to EnumValue.  Tried that and ended up with this which seems
to work:

for i in range(25):
try:
regEndeca = EnumKey(regpath,i)
print regEndeca
regValue = OpenKey(HKEY_LOCAL_MACHINE, key + "\\" + regEndeca)
for j in range(25):
try:
regstr,value,type = EnumValue(regValue,j)
print "Value Name: ", regstr, " - Value: ",value, " -
Data: ",type
except EnvironmentError:
print "There are", j,"values under",regEndeca
break
print "That was using EnumValue."
except EnvironmentError:
print "There are", i,"keys under",key
break
print "That was using EnumKey."

Thanks for the help

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