Is there a way I can write a script or batch file that I can make a desktop icon for that'll delete a specific registry key? I've got a couple key entry's I have to delete every 30 days or so.
Is there a way I can write a script or batch file that I can make a desktop icon for that'll delete a specific registry key? I've got a couple key entry's I have to delete every 30 days or so.
if you have windows scripting host installed you can write a vbs script *.vbs that will delete whatever key you want to delete. Here is an example
Save this file as a .vbs and run it. Let me know if it works I wrote this on the fly its been awhile since i've written any vbs and may have a syntax error or two.Code:'-------------------------------------------------------------------------------- 'Reg remover remover script '31/01/04 option explicit on error resume next dim ws,Rkey set ws = createobject("wscript.Shell") 'create system object Rkey= "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Spybot" 'Example register entry you want to delete dim test test = ws.regread(rKey) 'msgbox test if test <> "" then if msgbox("Are you sure you want to delete this key?",vbyesno) = vbyes then ws.regdelete(rKey) 'delete the key ws.popup Rkey & vbcr & " Has been deleted." quit end if else ws.popup "Key not found or action canceled." end if 'script Complete
Last edited by [AK]JD; 01-31-2004 at 09:26 AM.
Holy Cow, that was fast. Thanks!
Ok, here's the key I'm trying to kill:
[-HKEY_CLASSES_ROOT\CLSID\{1ABF72A3-8502-4EC4-A42A-BCE3755E0C70}]
I entered it into the right hole in your script, and the script does appear to activite, but I get the "Key not found"... message, so something's not quite right. Here's what I have typed total, I wonder if I missed a closeing quote:
'--------------------------------------------------------------------------------
'Reg remover remover script
'31/01/04
option explicit
on error resume next
dim ws,Rkey
set ws = createobject("wscript.Shell") 'create system object
Rkey= " -HKEY_CLASSES_ROOT\CLSID\{1ABF72A3-8502-4EC4-A42A-BCE3755E0C70} " 'TMPGen Key
dim test
test = ws.regread(rKey)
'msgbox test
if test <> "" then
if msgbox("Are you sure you want to delete this key?",vbyesno) = vbyes then
ws.regdelete(rKey) 'delete the key
ws.popup Rkey & vbcr & " Has been deleted."
quit
end if
else
ws.popup "Key not found or action canceled."
end if
'script Complete
your Rkey is not right, if you use regedit and go into the key you want to delete you can goto edit and copy key name to make sure its correct. It should look like this
Rkey= "HKEY_CLASSES_ROOT\CLSID\{1ABF72A3-8502-4EC4-A42A-BCE3755E0C70}" 'TMPGen Key
Hmm, still not working. I did a "copy key" and pasted that in directly. I don't know the syntax of vbs scripting, but making some guesses, your code logic appears sound....
I don't know what
dim.test means, but again, if I'm guessing the syntax of vbs scripting right, it looks like the problem is with the read test. What does the <> and "" do in the line:
If test <> "" then
Again, here's the entire text:
'--------------------------------------------------------------------------------
'Reg remover remover script - remove registry key for TMPGen
'31/01/04
option explicit
on error resume next
dim ws,Rkey
set ws = createobject("wscript.Shell") 'create system object
Rkey="HKEY_CLASSES_ROOT\CLSID\{1ABF72A3-8502-4EC4-A42A-BCE3755E0C70}"
dim test
test = ws.regread(rKey)
'msgbox test
if test <> "" then
if msgbox("Are you sure you want to delete this key?",vbyesno) = vbyes then
ws.regdelete(rKey) 'delete the key
ws.popup Rkey & vbcr & " Has been deleted."
quit
end if
else
ws.popup "Key not found or action canceled."
end if
'script Complete
for some reason the {} are causing the problem, I'll dig a little deeper into it.
over engineered.... thats what i get for trying to be too fancy. Here ya go this should work.
Code:'Reg remover remover script - remove registry key for TMPGen '31/01/04 option explicit on error resume next dim ws,Rkey set ws = createobject("wscript.Shell") 'create system object Rkey="HKEY_CLASSES_ROOT\CLSID\{1ABF72A3-8502-4EC4-A42A-BCE3755E0C70}" ws.regdelet(Rkey) msgbox "Done"
It's saying "Done" now, but it's still not deleting the registry item.
Use regcleaner!