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