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) 4 3357
Brad Tilley wrote: 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)
I figured it out. I'm using _winreg.OpenKey() as if it were
_winreg.CreateKey() and when one does that things don't work... it's
been a long day!
OpenKey(HKEY_LOCAL_MACHINE, x, 0, KEY_ALL_ACCESS)
CreateKey(HKEY_LOCAL_MACHINE, x)
Brad Tilley wrote: 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)
It took me DAYS to find this on the Net. The "trick" is you need
extra parameters on your OpenKey call, otherwise you get your error.
Try following, I think it will help.:
key = OpenKey(HKEY_LOCAL_MACHINE, x, 0, _winreg.KEY_SET_VALUE)
Good Luck,
Larry Bates
Larry Bates wrote: It took me DAYS to find this on the Net. The "trick" is you need extra parameters on your OpenKey call, otherwise you get your error.
Try following, I think it will help.:
key = OpenKey(HKEY_LOCAL_MACHINE, x, 0, _winreg.KEY_SET_VALUE)
Good Luck,
Larry Bates
Thanks, besides using OpenKey() correctly, I found that the values did
indeed have to be ints... here's a working function:
def log_limits():
logs = ['Application', 'Security', 'System']
vals = {'Retention':0, 'MaxSize':10223616, 'RestrictGuestAccess':1}
for l in logs:
x = r"SYSTEM\CurrentControlSet\Services\Eventlog\%s " % l
key = OpenKey(HKEY_LOCAL_MACHINE, x, 0, KEY_SET_VALUE)
for n,v in vals.iteritems():
SetValueEx(key,n,0,REG_DWORD,v)
CloseKey(key)
Brad Tilley wrote: Thanks, besides using OpenKey() correctly, I found that the values did indeed have to be ints...
Because you fixed the type to REG_DWORD in the SetValueEx call...
print _winreg.SetValueEx.__doc__
will show you the other possible types, you probably want REG_SZ.
-- Georges This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John Sellers |
last post by:
newbee question...I haven't worked on Python since Python 1.5.2
cygwin setup installs Python 2.3.2-1 on Windows XP
however:
$ python
Python 2.3.2 (#1, Oct 9 2003, 12:03:29)
|
by: Erick Bodine |
last post by:
I am trying to set a new environment variable on a W2k machine with
only partial success. The name("SSID") and value("ASIM") show up
correctly in the registry and when I go to "System...
|
by: Peter Olcott |
last post by:
www.halting-problem.com
|
by: Jon Davis |
last post by:
If I have a class with a virtual method, and a child class that overrides
the virtual method, and then I create an instance of the child class AS A
base class...
BaseClass bc = new ChildClass();...
|
by: Ammar |
last post by:
Dear All,
I'm facing a small problem.
I have a portal web site, that contains articles, for each article, the end
user can send a comment about the article.
The problem is:
I the comment length...
|
by: rtilley |
last post by:
A portion from the _winreg Documnetation:
-----------------------------------------------------------------
DeleteValue(key, value)
1. Removes a named value from a registry key. --> OK
2. key is...
|
by: RodneyWMcBride |
last post by:
Reply with quote Edit/Delete this post Delete this post
Post _winreg.SaveKey question
Does anyone know where I might find some sample code of using the
saveKey function? I am getting an error 5...
|
by: black_13 |
last post by:
I have included a small script the reproduces the error I am having in
larger script.
The line 'hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,name)'
seems
to be causing the error but im not...
|
by: Jonathan Fine |
last post by:
Hello
I'm using the _winreg module to change Windows registry settings, but
its rather low level, and I'd prefer to be working with something more
Pythonic.
Does anyone have any...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |