Results 1 to 10 of 10

Thread: Script to Delete a registry key?

  1. #1
    Administrator
    August Knights
    Assistant Recruiter

    [AK]Clay's Avatar
    Join Date
    Nov 2003
    Posts
    3,004

    Map Script to Delete a registry key?

    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.

  2. #2
    whats friendly fire ? [AK]JD's Avatar
    Join Date
    Sep 2003
    Location
    Langley, BC
    Posts
    513
    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

    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
    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.

    Last edited by [AK]JD; 01-31-2004 at 09:26 AM.

  3. #3
    Administrator
    August Knights
    Assistant Recruiter

    [AK]Clay's Avatar
    Join Date
    Nov 2003
    Posts
    3,004
    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

  4. #4
    whats friendly fire ? [AK]JD's Avatar
    Join Date
    Sep 2003
    Location
    Langley, BC
    Posts
    513
    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

  5. #5
    Administrator
    August Knights
    Assistant Recruiter

    [AK]Clay's Avatar
    Join Date
    Nov 2003
    Posts
    3,004

    Monitor

    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

  6. #6
    whats friendly fire ? [AK]JD's Avatar
    Join Date
    Sep 2003
    Location
    Langley, BC
    Posts
    513
    for some reason the {} are causing the problem, I'll dig a little deeper into it.

  7. #7
    whats friendly fire ? [AK]JD's Avatar
    Join Date
    Sep 2003
    Location
    Langley, BC
    Posts
    513
    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"

  8. #8
    Administrator
    August Knights
    Assistant Recruiter

    [AK]Clay's Avatar
    Join Date
    Nov 2003
    Posts
    3,004
    It's saying "Done" now, but it's still not deleting the registry item.

  9. #9

    August Knights
    The old Man in the War [AK]Rocks's Avatar


    Join Date
    Nov 2002
    Location
    Albany NY
    Posts
    1,837
    Use regcleaner!

  10. #10
    Who is Nuts and Abbadon? [AK]StitchJones's Avatar
    Join Date
    Oct 2002
    Location
    Ballston Spa NY
    Posts
    4,134
    #!/bin/perl
    use Win32:Registery
    $joke = "just kidding";
    print "use perl to do this\n";
    print "This is supposed to be used only as humor, not a script\n";
    print "but feel free to dump this to a .pl script and run it :-)\n";
    print "$joke\n";


Similar Threads

  1. Hello, please delete me if this is inappropriate
    By negative99 in forum August Knights Round Table
    Replies: 27
    Last Post: 10-18-2002, 07:00 PM
  2. buddy way point script
    By Pixelsponge in forum Tribes Series
    Replies: 8
    Last Post: 09-03-2001, 03:00 PM
  3. registry rollback
    By Wolff in forum Technical Support
    Replies: 4
    Last Post: 01-30-2001, 04:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •