Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > deleting registry keys and value

Reply
Thread Tools

deleting registry keys and value

 
 
sdb1031@gmail.com
Guest
Posts: n/a
 
      11-19-2005
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_MACHIN E)
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_MACHIN E)
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")

 
Reply With Quote
 
 
 
 
elbertlev@hotmail.com
Guest
Posts: n/a
 
      11-19-2005
Looks OK to me. Just tried on my network - works with no exceptions

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is Windows registry (Registry Keys) Omar Abid Windows 64bit 0 03-28-2008 04:25 PM
What is Windows registry (Registry Keys) Omar Abid Computer Support 0 03-28-2008 04:22 PM
Deleting a File from Hardrive and Deleting a SubKey in Registry Harry Barker C++ 2 04-19-2006 09:34 AM
Deleting Registry Keys Buckwheat Computer Support 8 03-02-2005 03:59 AM
deleting registry keys ron Computer Support 2 02-14-2004 03:49 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57