deleting registry keys and value

S

sdb1031

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")
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top