I am experiencing difficulty using _winreg.SaveKey to export a registry from a remote host. I am able to connect to and read the remote reg key, but I am getting a 'WindowsError [ErrNo 5] Access denied' when trying to perform the export to a file. The documentation reads that if using SaveKey to export a remote key that the 'file name' is relative. I understood this to mean that I could use a unc path to where I want to store the file. I am currently using a unc path, but I have tried to use a local path via a local drive letter, but have not been able to get around the access denied error message.

I am using ActivePython 1.2 (Python = 2.4.3). Below is a copy of my source code. Any assistance will be appreciated.

import os, string, sys, win32con, _winreg

def createFolder(path):
    if os.path.exists (path):
        pass    # do nothing
    else:
        os.mkdir(path)

def remoteSaveKey(host, subkey, file):
    rhostreg = _winreg.ConnectRegistry(host, _winreg.HKEY_LOCAL_MACHINE)
    remotekey = _winreg.OpenKey(rhostreg, subkey, 0, _winreg.KEY_ALL_ACCESS)
    _winreg.SaveKey(remotekey, file)

destsrvr = "\\\\server1\\backup$\\"
# Registry key (and all subkeys) to be processed for backup/restore
regpath = "Software\\Cisco Systems, Inc."

# Open hostfile and read hostnames into a list
readfile = open('d:\scripts\dev\SideAsrv.txt', 'r')
hostfile = []
for host in readfile:
    hostfile += [host.strip()]
   
readfile.close()

for srvname in hostfile:
    outputpath = destsrvr + srvname
    createFolder(outputpath)
    outputfile = outputpath + "\\" + srvname
    srvname = "\\\\" + srvname
    # Call the function to connect to and export the remote registry key
    output = remoteSaveKey(srvname, regpath, outputfile)
    # DEBUG
    print outputfile
    # Select the next host


Thanks,

Rodney McBride
_______________________________________________
ActivePython mailing list
ActivePython@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython

Reply via email to