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 programmaticall y 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\explor er2.exe 1
Traceback (most recent call last):
File "C:\Documen ts and Settings\sbrile y.STAT\Desktop\ testreg.py",
line 12, in
?
DeleteValue(aKe y, 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 ("remotecompute r",HKEY_LOCAL_M ACHINE)
aKey = OpenKey(aReg, r"SOFTWARE\Micr osoft\Windows\C urrentVersion\R un",
0, KEY_WRITE)
SetValueEx(aKey ,"MyNewKey", 0, REG_SZ, r"c:\winnt\expl orer2.exe")
aReg = ConnectRegistry ("remotecompute r",HKEY_LOCAL_M ACHINE)
aKey = OpenKey(aReg, r"SOFTWARE\Micr osoft\Windows\C urrentVersion\R un",
KEY_ALL_ACCESS)
n,v,t = EnumValue(aKey, 5)
#print out the key
print n, v, t
CloseKey(aKey)
aKey = OpenKey(aReg, r"SOFTWARE\Micr osoft\Windows\C urrentVersion\R un",
KEY_ALL_ACCESS)
DeleteValue(aKe y, "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 programmaticall y 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\explor er2.exe 1
Traceback (most recent call last):
File "C:\Documen ts and Settings\sbrile y.STAT\Desktop\ testreg.py",
line 12, in
?
DeleteValue(aKe y, 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 ("remotecompute r",HKEY_LOCAL_M ACHINE)
aKey = OpenKey(aReg, r"SOFTWARE\Micr osoft\Windows\C urrentVersion\R un",
0, KEY_WRITE)
SetValueEx(aKey ,"MyNewKey", 0, REG_SZ, r"c:\winnt\expl orer2.exe")
aReg = ConnectRegistry ("remotecompute r",HKEY_LOCAL_M ACHINE)
aKey = OpenKey(aReg, r"SOFTWARE\Micr osoft\Windows\C urrentVersion\R un",
KEY_ALL_ACCESS)
n,v,t = EnumValue(aKey, 5)
#print out the key
print n, v, t
CloseKey(aKey)
aKey = OpenKey(aReg, r"SOFTWARE\Micr osoft\Windows\C urrentVersion\R un",
KEY_ALL_ACCESS)
DeleteValue(aKe y, "MyNewKey")
Comment