473,372 Members | 1,135 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

_winreg.saveKey question


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 access denied and I think
that it is coming from the way I am specifying the filename as in
_winreg.SaveKey(key, filename). The docs mention that if the key is to
a remote host (which it is in my case) that the path is relative. I
read this as meaning that I should use a unc path back to where I want
to save the registry key file. Here is a section of the code I am
using:

def remoteSaveKey(host, key, file):
rhostreg = _winreg.ConnectRegistry(host, _winreg.HKEY_LOCAL_MACHINE)
remotekey = _winreg.OpenKey(rhostreg, key)
_winreg.SaveKey(remotekey, file)
.... from main():

readfile = open('hostlist.txt', 'r')
hostfile = []
for host in readfile:
hostfile += [host.strip()]

for srvname in hostfile:
outputpath = destsrvr + srvname # destsrvr is server/share
outputfile = outputpath + "\\" + srvname
output = remoteSaveKey(hostname, regpath, outputfile)

I am able to connect to the registry and I believe that the key is
being specified correctly, but I am getting the following error:

Traceback (most recent call last):
File "main.py", line 40, in ?
output = remoteSaveKey(srvname, regpath, outputfile)
File "main.py", line 17, in remoteSaveKey
_winreg.SaveKey(remotekey, file)
WindowsError: [Errno 5] Access is denied

I have searched but have only been able to find documentation with
little to no examples on how to implement the SaveKey function with a
remote host. Any help will be appreciated.

thx

Oct 23 '06 #1
2 2577
remotekey = _winreg.OpenKey(rhostreg, key)
Try adding the sam=_winreg.KEY_SET_VALUE parameter.

Help on built-in function OpenKey in module _winreg:

OpenKey(...)
key = OpenKey(key, sub_key, res = 0, sam = KEY_READ) - Opens the
specified key.

key is an already open key, or any one of the predefined HKEY_* constants.
sub_key is a string that identifies the sub_key to open
res is a reserved integer, and must be zero. Default is zero.
sam is an integer that specifies an access mask that describes the desired
security access for the key. Default is KEY_READ

The result is a new handle to the specified key
If the function fails, an EnvironmentError exception is raised.
The default is KEY_READ so you can't update.

-Larry Bates
Oct 23 '06 #2
remotekey = _winreg.OpenKey(rhostreg, key)
Try adding the sam=_winreg.KEY_SET_VALUE parameter.

Help on built-in function OpenKey in module _winreg:

OpenKey(...)
key = OpenKey(key, sub_key, res = 0, sam = KEY_READ) - Opens the
specified key.

key is an already open key, or any one of the predefined HKEY_* constants.
sub_key is a string that identifies the sub_key to open
res is a reserved integer, and must be zero. Default is zero.
sam is an integer that specifies an access mask that describes the desired
security access for the key. Default is KEY_READ

The result is a new handle to the specified key
If the function fails, an EnvironmentError exception is raised.
The default is KEY_READ so you can't update.

-Larry Bates
Oct 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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)
1
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...
4
by: Brad Tilley | last post by:
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: ...
3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
0
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...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
2
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.