469,293 Members | 1,335 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,293 developers. It's quick & easy.

_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 2360
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by John Sellers | last post: by
4 posts views Thread by Brad Tilley | last post: by
3 posts views Thread by Stevey | last post: by
reply views Thread by rtilley | last post: by
53 posts views Thread by Jeff | last post: by
2 posts views Thread by Jonathan Fine | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.