deleting registry keys and value

Discussion in 'Python' started by sdb1031@gmail.com, Nov 19, 2005.

  1. Guest

    Hi,

    I am trying to learn how to write, change and delete registry keys and
    values of a remote computer via Python's _winreg module. So far, I've
    been able to programmatically create a value and read the value.
    However, I am unable to figure out how to delete the value. Using the
    following code, I get the following output:

    MyNewKey c:\winnt\explorer2.exe 1
    Traceback (most recent call last):
    File "C:\Documents and Settings\sbriley.STAT\Desktop\testreg.py",
    line 12, in
    ?
    DeleteValue(aKey, r"MyNewKey")
    WindowsError: [Errno 5] Access is denied

    I have administrative access on the target machine and can delete the
    key manually by connecting remotely using regedit. Here's the code.
    BTW, does anyone know how to provide credentials to the remote system
    if it has a different user/pass than the host system? I don't believe
    that ConnectRegistry() will allow this.

    Thanks,

    Steve

    from _winreg import *
    #create the key
    aReg = ConnectRegistry("remotecomputer",HKEY_LOCAL_MACHINE)
    aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",
    0, KEY_WRITE)
    SetValueEx(aKey,"MyNewKey",0, REG_SZ, r"c:\winnt\explorer2.exe")

    aReg = ConnectRegistry("remotecomputer",HKEY_LOCAL_MACHINE)
    aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",
    KEY_ALL_ACCESS)
    n,v,t = EnumValue(aKey,5)
    #print out the key
    print n, v, t
    CloseKey(aKey)

    aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",
    KEY_ALL_ACCESS)
    DeleteValue(aKey, "MyNewKey")
     
    , Nov 19, 2005
    #1
    1. Advertising

  2. Guest

    Looks OK to me. Just tried on my network - works with no exceptions
     
    , Nov 19, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HK
    Replies:
    1
    Views:
    3,651
    Cowboy \(Gregory A. Beamer\)
    Apr 1, 2004
  2. Replies:
    0
    Views:
    757
  3. Leny
    Replies:
    3
    Views:
    16,935
    Daniel
    Feb 1, 2005
  4. Harry Barker
    Replies:
    2
    Views:
    521
    Alf P. Steinbach
    Apr 19, 2006
  5. Collin Miller
    Replies:
    10
    Views:
    609
    Roger Pack
    Jul 9, 2010
Loading...

Share This Page