Results 1 to 10 of 10

Thread: list all keys, subkeys and values in registry hive

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    list all keys, subkeys and values in registry hive

    here is a recursive scripting method to get all keys and subkeys in a hive starting from root or any level
    takes a while, probably should have a doevents somewhere, to prevent computer lockup while running
    vb Code:
    1. Sub getsubkeys(hkey As Long, strpath As String, sk As Variant)
    2. Dim strkeypath As String, subkey As Variant, arrsubkeys As Variant
    3. strkeypath = strpath
    4. If Not Len(sk) = 0 And Not Len(strpath) = 0 Then strkeypath = strpath & "\"
    5. strkeypath = strkeypath & sk
    6. oreg.EnumKey hkey, strkeypath, arrsubkeys
    7. If Not IsNull(arrsubkeys) Then
    8. For Each subkey In arrsubkeys
    9.     Debug.Print strkeypath & "\" & subkey     ' or print to form or whatever
    10.       ' for speed considerations should be stored to memory (variable) and written to whatever in sections, trying to read the entire registry into memory may or may not be possible, depending on machine configuration
    11.     getsubkeys hkey, strkeypath, subkey
    12. Next
    13. End If
    14. End Sub
    15.  
    16. ' call like
    17. Sub yy()
    18. Const HKEY_CURRENT_USER As Long = &H80000001
    19. strComputer = "."
    20. Set oreg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
    21. getsubkeys HKEY_CURRENT_USER, "", ""   ' get from root level
    22. 'or
    23. getsubkeys HKEY_CURRENT_USER, "software\adobe", ""   ' starting at adobe
    24. Set oreg =  Nothing
    25. End Sub
    declare oreg as object in the general section
    Last edited by westconn1; Dec 24th, 2009 at 07:36 AM. Reason: modified function arguments
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width