Page 1 of 1

RegDeleteKeysRecursive

Posted: Mon Sep 15, 2003 3:23 pm
by Fred
Code updated For 5.20+

Deletes a registry key recursive, with all its childs..

Code: Select all

;
; Recursive registry delete routine, to be compatible with all windows versions
;
Procedure RegDeleteKeysRecursive(StartKey, pKeyName$)

  Result = ~#ERROR_SUCCESS
  
  If pKeyName$
  
    Result = RegOpenKeyEx_(StartKey, pKeyName$, 0, #KEY_ENUMERATE_SUB_KEYS | #DELETE, @Key )
    If Result = #ERROR_SUCCESS
    
      SubKeyName$ = Space(512)
    
      While Result = #ERROR_SUCCESS And Quit = 0
        SubKeyLength = 512
        Result = RegEnumKeyEx_(Key, SubKeyIndex, SubKeyName$, @SubKeyLength, 0, 0, 0, 0)
        SubKeyIndex+1
        
        If Result = #ERROR_NO_MORE_ITEMS
          Result = RegDeleteKey_(StartKey, pKeyName$)
          Quit = 1
          
        ElseIf Result = #ERROR_SUCCESS
                 
          SubKeyIndex-1
          If RegDeleteKeysRecursive(Key, SubKeyName$)
            Result = #ERROR_SUCCESS;
          EndIf
        EndIf
      Wend
      
      RegCloseKey_(Key)
    EndIf
  EndIf
    
  If Result = #ERROR_SUCCESS
    ProcedureReturn 1
  Else
    ProcedureReturn 0
  EndIf 

EndProcedure


; Test here... WARNING, it could be dangerous !
;
RegDeleteKeysRecursive(#HKEY_CURRENT_USER, "Software\YourFavoriteSoftwareHere")


Posted: Mon Sep 15, 2003 4:54 pm
by GPI
Short copy out of my IncludePack1:

Code: Select all

Procedure Reg_DeleteKeyWithAllSub(topKey,sKeyName.s,ComputerName.s)
  i=0
  a$=""
  Repeat
    b$=a$
    a$=Reg_ListSubKey(topKey,sKeyName,0,"")
    If a$<>""
      Reg_DeleteKeyWithAllSub(topKey,sKeyName+"\"+a$,"")
    EndIf
  Until a$=b$
  Reg_DeleteKey(topKey, sKeyName, ComputerName) 
EndProcedure
But this function need the rest of the registry.pbi

GPI

Posted: Tue Sep 16, 2003 6:12 am
by sec
:) simplest

Code: Select all

If OpenLibrary(0, "SHLWAPI.DLL")

  *F = IsFunction(0, "SHDeleteKeyA")
  If *F
    CallFunctionFast(*F,#HKEY_CURRENT_USER, "Software\test")
  EndIf
  
  CloseLibrary(0)
EndIf
why don't support "API in SHLWAPI.DLL"?
EDIT: dlls usually used is better :oops: (as Fred did)

Posted: Tue Sep 16, 2003 5:26 pm
by Fred
sec wrote: why don't support "API in SHLWAPI.DLL"?
EDIT: dlls usually used is better :oops: (as Fred did)
Because of this:

Minimum DLL Version shlwapi.dll version 4.71 or later
Custom Implementation No
Header shlwapi.h
Import library shlwapi.lib
Minimum operating systems Windows 2000, Windows NT 4.0 with Internet Explorer 4.0, Windows 98, Windows 95 with Internet Explorer 4.0

:)