Const HKEY_CLASSES_ROOT = &H80000000 Const HKEY_CURRENT_USER = &H80000001 Const HKEY_LOCAL_MACHINE = &H80000002 Const HKEY_USERS = &H80000003 Const HKEY_CURRENT_CONFIG = &H80000005 regKey = "SOFTWARE\CerroTorre\SelfADSI\" RegDeleteTree HKEY_LOCAL_MACHINE, regKey Sub RegDeleteTree(hiveParam, keyParam) Dim aSubKeys, strKey, strSubKey, ccode, reo ' get the registry WMI provider Set reo = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") ' we add a backslash in tail If (Right(keyParam,1)<>"\") Then keyParam = keyParam & "\" On Error Resume Next ' deactivate RunTime Errors ccode = reo.EnumKey(hiveParam, keyParam, aSubKeys) ' check for key content If ccode = 0 And IsArray(aSubKeys) Then For Each strSubKey In aSubKeys If Err.Number <> 0 Then ' wrong key or other error => exit Err.Clear Exit Sub End If RegDeleteTree hiveParam, keyParam & strSubKey ' for each content do recursion Next End If reo.DeleteKey hiveParam, keyParam ' last action: delete the key End Sub s