Mass Registry Key Delete

By | July 24, 2006

Do you need to delete a lot of registry keys and all of its subkeys all the time?
This script removes registry keys and recursively remove all of the subkeys listed under the parent key.
Just drag and drop!

This script will require two files.

The first one is the workhorse. It will delete reg keys and all subkeys.
The second file is a simple text file with a list of reg keys to delete

 

———-COPY EVERYTHING BELOW THIS LINE———-

‘This script will delete registry keys from the local computer.
‘Just drag and drop a .txt file onto it and the keys will be deleted.
‘All subkeys are also deleted.
‘By Chey Harden 7-25-06

Const HKCR   = &H80000000
Const HKCU   = &H80000001
Const HKLM   = &H80000002
Const HKU    = &H80000003
Const HKCC   = &H80000005
Const ForReading = 1
Dim strHive, arrPath, strNewReg, strChar

sComputer = “.”
strChar = “”
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set oReg = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” _
& sComputer & “\root\default:StdRegProv”)
Set objArgs = Wscript.Arguments
Set objTextFile = objFSO.OpenTextFile(objArgs(0), ForReading)

Do Until objTextFile.AtEndOfStream
strReg = objTextFile.Readline
‘Wscript.Echo strReg & ” From Text File”

arrPath = Split(strReg, “\”)
‘Wscript.Echo ArrPath(0) & ” From Array”
strNewReg = Replace(strReg, ArrPath(0) & “\”, strChar)
‘Wscript.Echo strNewReg & ” New Key Path”

Select Case ArrPath(0)

Case “HKEY_CURRENT_USER”
DeleteRegistryKey HKCU, strNewReg

Case “HKEY_LOCAL_MACHINE”
DeleteRegistryKey HKLM, strNewReg

Case “HKEY_CLASSES_ROOT”
DeleteRegistryKey HKCR, strNewReg

Case “HKEY_USERS”
DeleteRegistryKey HKU, strNewReg

Case “HKEY_CURRENT_CONFIG”
DeleteRegistryKey HKCC, strNewReg

End Select
Loop

MsgBox “Done…”

Sub DeleteRegistryKey(ByVal sHive, ByVal sKey)
Dim aSubKeys, sSubKey, iRC
‘On Error Resume Next
iRC = oReg.EnumKey(sHive, sKey, aSubKeys)
If iRC = 0 And IsArray(aSubKeys) Then
For Each sSubKey In aSubKeys
If Err.Number <> 0 Then
Err.Clear
Exit Sub
End If
‘Wscript.Echo sHive, sKey & “\” & sSubKey & ” From Sub”
DeleteRegistryKey sHive, sKey & “\” & sSubKey
Next
End If
oReg.DeleteKey sHive, sKey
End Sub

 

 

 

———-COPY EVERYTHING ABOVE THIS LINE———-

 

Next you’ll need a txt file to read your reg keys from.
Below is an EXAMPLE.
Copy the text below into notepad and name the file <Some File Name>.txt

———-COPY EVERYTHING BELOW THIS LINE———-

HKEY_CURRENT_USER\SOFTWARE\BrokenSoftware
HKEY_LOCAL_MACHINE\SOFTWARE\BrokenSoftware

———-COPY EVERYTHING ABOVE THIS LINE———-

Just drag and drop this txt file onto the script for the action to begin!

PLEASE MAKE SURE NO WORD WRAPPING IS HAPPENING IN YOUR NOTEPAD!!!

*Do not put blank lines between registry keys!
*One reg key per line
*Wild card characters do not work!
*** Remember this will recursively remove reg keys!

This information is provided “AS IS” with no warranties expressed or implied.

Leave a Reply

Your email address will not be published. Required fields are marked *