B
Brad Tilley
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',
'RestrictGuestAccess':'1'}
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:
SetValueEx(key,n,0,REG_DWORD,v)
CloseKey(key)
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',
'RestrictGuestAccess':'1'}
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:
SetValueEx(key,n,0,REG_DWORD,v)
CloseKey(key)