VBScript to delete Novell registry keys

Recently I created a script for a colleague that will recursively delete some Novell registry keys if found in HKEY_USERS.  It doesn’t check if the key exists first, it’ll just try to delete it.  However, if the key does exist and does have subkeys, it will delete the subkeys first. Hopefully this will get the job done if you need something like this.  To test it first, simply uncomment the wscript.echo statements and run on a test system.

'On Error Resume Next 
Const HKU = &H80000003 
Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv") 
' Delete first key 
strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Novell GroupWise" 
objRegistry.EnumKey HKU, "", arrSubkeys1 
For Each strSubkey in arrSubkeys1 
 'wscript.echo cstr(strSubkey) 
 DeleteSubkeys HKU, cstr(strSubkey) & "\" & strKeypath  
Next 
' Delete second key 
strKeyPath = "Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Novell Default Settings" 
objRegistry.EnumKey HKU, "", arrSubkeys2 
For Each strSubkey in arrSubkeys2 
 'wscript.echo cstr(strSubkey) 
 DeleteSubkeys HKU, cstr(strSubkey) & "\" & strKeypath  
Next 
wscript.quit 0 
'============================================================ 
Sub DeleteSubkeys(HKU, strKeyPath) 
 objRegistry.EnumKey HKU, 
 strKeyPath, arrSubkeys3 
 If IsArray(arrSubkeys3) Then 
 For Each strSubkey In arrSubkeys3 
 DeleteSubkeys HKU, strKeyPath & "\" & strSubkey  
 Next 
 End If 
 objRegistry.DeleteKey HKU, strKeyPath z
 'wscript.echo "Deleted: " & strKeyPath 
End Sub 

Filed under: Scripting

email

Written by , Posted .