Results 1 to 7 of 7

Thread: node structure in registry

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    Hooglede (belgium)
    Posts
    63

    Question

    Hey,
    I have a structure in the registry like this:
    text1
    --- text2
    -------text3
    -------text4
    Does someone know how I can retrieve the structure from
    the registry. Meaning, I want to retrieve text3,text4 and
    this without knowing what text3 and text4 are.
    More specific, what are the child nodes of text2.

    THANKS.

  2. #2
    Addicted Member
    Join Date
    Sep 2000
    Posts
    138
    You can use the Windows API RegEnumKeyEx function to enumerate any key or subkey.

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    Hooglede (belgium)
    Posts
    63

    Smile

    Thanks for the reply,
    but could I get a little more help with this one.
    I am not programming so long with API calls.

    THANKS

  4. #4
    Lively Member
    Join Date
    May 1999
    Location
    belgium
    Posts
    74
    I'm also not familiar with API-controls. Sorry

  5. #5
    Addicted Member
    Join Date
    Sep 2000
    Posts
    138
    That's a long story. I'll see whether I can write a code to you in an hour.

  6. #6
    Addicted Member
    Join Date
    Sep 2000
    Posts
    138
    The following code shows how to attempt the registry. Just copy and paste it under your form. I have tested it.
    Code:
    Option Explicit
        '
        '--------------------------------------------------------
        ' Example to attempt the registry
        ' List all the subkeys under HKEY_LOCAL_MACHINE\Software
        ' Make a big text box with its default name and with the
        ' MultiLine property set to True and ScrollBars property
        ' set to 2 (Vertical)
        ' Make a CommandButton with its default name
        '--------------------------------------------------------
        
    'Three API functions needed to enumerate keys
    Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
        "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
        ByVal ulOptions As Long, ByVal samDesired As Long, _
        phkResult As Long) As Long
    
    Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias _
        "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, _
        ByVal lpName As String, lpcbName As Long, ByVal lpReserved _
        As Long, ByVal lpClass As String, lpcbClass As Long, _
        lpftLastWriteTime As FILETIME) As Long
    
    Private Declare Function RegCloseKey Lib "advapi32.dll" _
        (ByVal hKey As Long) As Long
    
    'Type needed by a function
    Private Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
    End Type
    Dim typFileTime As FILETIME
    
    'Constants needed by the functions
    Private Const ERROR_SUCCESS = 0&
    Private Const READ_CONTROL = &H20000
    Private Const HKEY_LOCAL_MACHINE = &H80000002
    Private Const KEY_QUERY_VALUE = &H1
    Private Const KEY_ENUMERATE_SUB_KEYS = &H8
    Private Const KEY_NOTIFY = &H10
    Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
    Private Const SYNCHRONIZE = &H100000
    Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE _
        Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
    
    Private Sub Command1_Click()
        
        End
        
    End Sub
    
    Private Sub Form_Load()
        '
        '--------------------------------------------------------
        'Step 1 -- Open key and get the handle
        '--------------------------------------------------------
        
        'Variables for RegOpenKeyEx
        Dim lngKeyHandle As Long
        Dim strSubKey As String
        Dim lngRetVal As Long
        
        'Variable for RegEnumKeyEx
        Dim lngIndex As Long
        Dim strKeyName As String
        Dim lngKeyLen As Long
        Dim strClassName As String
        Dim lngClassLen As Long
        
        strSubKey = "Software"
        
        'Open the Subkey and get its handle
        lngRetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strSubKey, 0, KEY_READ, lngKeyHandle)
        
        If lngRetVal <> ERROR_SUCCESS Then MsgBox "Error in Opening Key!"
        
        'Show the main key and subkey
        Text1.Text = "HKEY_LOCAL_MACHIN\Software" & vbNewLine
        '
        '--------------------------------------------------------
        'Step 2 -- List all the subkeys
        '--------------------------------------------------------
        While lngRetVal = ERROR_SUCCESS
            lngKeyLen = 1000
            lngClassLen = 1000
            strKeyName = String(lngKeyLen, 0)
            strClassName = String(lngClassLen, 0)
            lngRetVal = RegEnumKeyEx(lngKeyHandle, lngIndex, strKeyName, _
                lngKeyLen, 0, strClassName, lngClassLen, typFileTime)
            lngIndex = lngIndex + 1
            Text1.Text = Text1.Text & Left(strKeyName, lngKeyLen) & vbNewLine
        Wend
        '
        '--------------------------------------------------------
        'Step 3 -- Close the key
        '--------------------------------------------------------
        RegCloseKey lngKeyHandle
        
    End Sub
    ------------------------------------------------
    Many thanks to jbart who told me how to use the vb code tags.

  7. #7

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    Hooglede (belgium)
    Posts
    63

    Thumbs up

    Thanks

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