_winreg problem

Brad Tilley bradtilley at gmail.com
Thu Oct 7 23:13:16 CEST 2004

The below function fails with this error:
ValueError: Could not convert the data to the specified type.

The problem appears to be the v variable. When I make v an int, I get:
WindowsError: [Error 5] Access is denied. This makes sense to me as the 
_winreg docs says that value (v) in SetvalueEx should be a string, but I 
do not understand why it  gives the "ValueError" error when I make it a 
string. Also, I can do one key (Log) at a time, but not iterate over all 
of them like I'd like to do. I've checked it with print statements... 
every thing looks right.

Any suggestions?

def log_limits():       ## 18
     ## For winXP SP2 & Python 2.3.4
     ## set log limits on EventLogs, keep guests out of logs and set 
them to overwrite as needed.
     logs = ['Application', 'Security', 'System']
     vals = {'Retention':'0', 'MaxSize':'10223616', 
     for l in logs:
         x = r"SYSTEM\CurrentControlSet\Services\Eventlog\%s" % l
         ## This print shows I'm iterating of the logs correctly.
         print x
         key = OpenKey(HKEY_LOCAL_MACHINE, x)
         for n,v in vals.iteritems():
             ## This print shows I'm associating the value pairs with 
each Log
             print n,v
             ## Here is where the failure occurs... the v at the end:

More information about the Python-list mailing list