_winreg newbie question
Joe Green
the_3_project at yahoo.com
Tue Apr 29 05:39:07 EDT 2003
The previous examples were incomplete (and contained errors). Here is
a more complete example:
# pyreged.py
from myregedit import *
def main():
"Main() function"
key='LOCAL_MACHINE'
subkey='SOFTWARE'
myr = myregedit()
keylist = myr.IterKeys(key=key, subkey=subkey)
if (keylist):
print keylist
else:
print "Unable to iterate keys"
if __name__ == "__main__":
main()
# myregedit.py
import sys, string
from _winreg import *
class myregedit:
def __init__(self, compname=None, debug=None):
"Class initilization 'constructor'"
try:
self.LOCAL_MACHINE = ConnectRegistry(compname,
HKEY_LOCAL_MACHINE)
self.CURRENT_CONFIG = ConnectRegistry(compname,
HKEY_CURRENT_CONFIG)
self.CURRENT_USER = ConnectRegistry(compname, HKEY_CURRENT_USER)
self.DYN_DATA = ConnectRegistry(compname, HKEY_DYN_DATA)
self.PERFORMANCE = ConnectRegistry(compname,
HKEY_PERFORMANCE_DATA)
self.USERS = ConnectRegistry(compname, HKEY_USERS)
except:
print "Unable to connect to the registry."
sys.exit(1)
self.reg = [self.LOCAL_MACHINE, self.CURRENT_CONFIG,
self.CURRENT_USER,
self.DYN_DATA, self.PERFORMANCE, self.USERS]
def IterKeys(self, key=None, subkey=None):
"Returns type and data of a given value"
mykey=-1
if (key is "LOCAL_MACHINE"):
print "HEYU!"
mykey = 0
elif (key is "CURRENT_CONFIG"):
mykey = 1
elif (key is "CURRENT_USER"):
mykey = 2
elif (key is "DYN_DATA"):
mykey = 3
elif (key is "PERFORMANCE_DATA"):
mykey = 4
elif (key is "USERS"):
mykey = 5
else:
print "unableto assign mykey any value other than -1"
print "[%s]\t[%s]\t[%d]" % (key,subkey,mykey)
if (mykey is -1):
return None
subkeylist = []
try:
i = 0
while 1:
subkeylist.append(EnumKey(OpenKey(self.reg[mykey], subkey),
i))
i += 1
except EnvironmentError:
pass
return subkeylist
-------------
Doesn't make sense to me, I've been banging my head against the wall
for several hours now! I can't figure it out.. and I know it's
something very simple that I'm overlooking. I just don't see staring
at it any longer to be productive :)
Thanks
More information about the Python-list
mailing list