• 0

Find and delete registry keys/values


Question

Hi. I'm not too brilliant with VBScript, so please bear with me. I'm trying to create a script to search for xyz value in the registry and delete it from a target machine.

I'd like the process to be:

Box to input xyz

Box to input target machine name

Scan target registry and delete the value, keep scanning until all are deleted.

Report how many deleted or report if none found.

Is this possible?

So far I have:

Set WshShell = WScript.CreateObject("WScript.Shell")
Set DelReg = GetObject ("WinMgmts:{impersonationLevel=impersonate}!//./root/default:StdRegProv")

'Constants for WMI StdRegProv
Const HKCU = &H80000001
Const HKLM = &H80000002
Const HK_USERS = &H80000003

'On Error Resume Next

sStartKeyPath = "" 'Sets the search to start from the root of the registry

Do while regkey = ""
regkey = InputBox("What would you like to search the registry for?")
if regkey = "" then
msgbox "Please enter search criteria."
End if
Loop

DelReg.DeleteValue regkey[/CODE]

At the moment I can't even get it to search and delete a key from my own machine.

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Here is a VBS script that I wrote to help you handle getting the Registry Key and Computer Name.

The X and Cancel will not close the Inputbox. The only way to cancel is to type in Exit or Quit.

'-> Variables For Run Time
Dim Input, R1, R2, Tx
Tx = "Type either Exit or Quit to cancel and do nothing"

'-> Get The Key Name
  UserIn("Type in the Registry Key that you want to search for?" & _
         vbCrLf & Tx)
  R1 = Input

'-> Get The Computer Name
  UserIn("Type in the Computer Name for this script?" & _
         vbCrLf & Tx)         
  R2 = Input

'-> Inputboxes Return
   MsgBox "Registry : " & R1 & vbCrLf & _
          "Computer : " & R2, 4128,"Demo Return"

'-> Get User Input
  Function UserIn(Msg)    
   Input = Inputbox(Msg,"","",5500,5500)   
    If LCase(InStr(1,Input,"exit",1)) Or _
       LCase(InStr(1,Input,"quit",1)) Then
     WScript.Quit(0) 
    End If 
    If Input <> "" And Len(Input) > 3 Then Exit Function
   UserIn(Msg) 
  End Function

Link to comment
Share on other sites

  • 0

Thanks very much for this. :) I will take a look next week when I'm back at work.

Link to comment
Share on other sites

  • 0

I have the part of getting the user input for what machine and the key to search for. However I need to know how to delete that key from that computer.

Link to comment
Share on other sites

This topic is now closed to further replies.