_winreg.saveKey question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RodneyWMcBride@gmail.com

    #1

    _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(h ost, key, file):
    rhostreg = _winreg.Connect Registry(host, _winreg.HKEY_LO CAL_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(h ostname, 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(s rvname, 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

  • Larry Bates

    #2
    Re: _winreg.saveKey question

    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 EnvironmentErro r exception is raised.


    The default is KEY_READ so you can't update.

    -Larry Bates

    Comment

    • Larry Bates

      #3
      Re: _winreg.saveKey question

      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 EnvironmentErro r exception is raised.


      The default is KEY_READ so you can't update.

      -Larry Bates

      Comment

      Working...