VBScript to delete Novell registry keys

Posted on Updated on

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
    'wscript.echo "Deleted: " & strKeyPath
End Sub
Advertisements

3 thoughts on “VBScript to delete Novell registry keys

    Rich said:
    December 9, 2013 at 2:41 pm

    I dont really understand this script. Is this part of the script or should this be deleted as well?

    “‘ Delete first key “

      N. Moseley responded:
      December 11, 2013 at 5:23 pm

      Rich, I can’t blame you – there was a major formatting problem that I needed to fix. Check it out now.

        Rich said:
        December 11, 2013 at 5:56 pm

        Thank you sir that is much better and works for me!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s