Results 1 to 2 of 2

Thread: reading registry sub keys

  1. #1

    Thread Starter
    Lively Member Feras's Avatar
    Join Date
    Sep 2000
    Location
    Homs, Syria
    Posts
    85

    How can I read the sub keys of a given registry path?
    Yesterday is history ... Tomorrow is mistry .. Today is a gift.

    VB6 , intermidiat

  2. #2
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    use the RegEnumKeys API

    This is copied strait from vbapi.com, make sure to add the declares:

    Code:
    ' Enumerate the subkeys under HKEY_LOCAL_MACHINE\Software.  The name
    ' and class of each subkey is displayed for the user.  Note the use of the loop which
    ' starts at 0 and keeps incrementing the index until no more subkeys exist.
    Dim keyname As String  ' receives name of each subkey
    Dim keylen As Long  ' length of keyname
    Dim classname As String  ' receives class of each subkey
    Dim classlen As Long  ' length of classname
    Dim lastwrite As FILETIME ' receives last-write-to time, but we ignore it here
    Dim hkey As Long  ' handle to the HKEY_LOCAL_MACHINE\Software key
    Dim index As Long  ' counter variable for index
    Dim retval As Long  ' function's return value
    
    ' Open the desired registry key.  Note the access level requested.
    retval = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software", 0, KEY_ENUMERATE_SUB_KEYS, hkey)
    ' Test to make sure the key was opened successfully.
    If retval <> 0 Then
      Debug.Print "Registry key could not be opened -- aborting."
      End  ' terminate the program
    End If
    
    ' List through each possible subkey.  Note how the strings receiving the information
    ' must be reinitialized each loop iteration.
    index = 0  ' initial index value
    While retval = 0  ' while we keep having success (retval equals 0 from the above API call)
      keyname = Space(255): classname = Space(255)  ' make room in string buffers
      keylen = 255: classlen = 255  ' identify the allocated space
      ' Get information about the next subkey, if one exists.
      retval = RegEnumKeyEx(hkey, index, keyname, keylen, ByVal 0, classname, classlen, lastwrite)
      If retval = 0  ' only display info if another subkey was found
        ' Extract the useful information from the string buffers.
        keyname = Left(keyname, keylen)  ' trim off the excess space
        classname = Left(classname, classlen)
        ' Display the returned information.
        Debug.Print "HKEY_LOCAL_MACHINE\Software\"; keyname  ' display full subkey name
        Debug.Print "  (class: "; classname  ' display subkey's class
      End If
      index = index + 1  ' increment the index counter
    Wend  ' end the loop
    
    ' Close the registry key after enumeration is complete.
    retval = RegCloseKey(hkey)
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

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