Results 1 to 7 of 7

Thread: [RESOLVED] get names of all registry keys

  1. #1

    Thread Starter
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,842

    Resolved [RESOLVED] get names of all registry keys

    Hi,

    I'm trying to develop a method to read all the names of the keys in the registry, specifically thoes in the Current_User hive.

    There are plenty of examples to be found but they all seem to start by suggesting something similar to:
    Code:
     Dim rKey As RegistryKey
    Each time I try this, I get an error message...
    RegistryKey is not defined
    ...so I didn't start with the definition because 'For Each' doesn't seem to expect one.

    I started off trying:
    Code:
        Private Sub Button2_Click() Handles Button2.Click
            For Each rKey In My.Computer.Registry("HKEY_CURRENT_USER")
                rKey = GetSubKeyNames
                If rKey IsNot Nothing Then ListBox1.Items.Add(rKey)
            Next
        End Sub
    But I get an error message:
    'Public ReadOnly Property Registry As RegistryProxy' has no perameters and it's return type cannot be indexed.
    Most of the examples I find explain how to find, or check the existence of a specific key or subkey, but I'm trying to list all keys.


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,246

    Re: get names of all registry keys

    That's because...

    Code:
    Dim rKey As RegistryKey
    Needs an import...

    Code:
    Imports Microsoft.Win32

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,246

    Re: get names of all registry keys

    I can see all kinds of wrong with the rest of your code there, but the Import will get you started

  4. #4

    Thread Starter
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,842

    Re: get names of all registry keys

    Quote Originally Posted by .paul. View Post
    That's because...

    Code:
    Dim rKey As RegistryKey
    Needs an import...

    Code:
    Imports Microsoft.Win32
    Thanks Paul,

    I looked for an import but didn't find one anywhere.


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,246

    Re: get names of all registry keys

    Name:  23-05-2020_01.11.45.png
Views: 51
Size:  1.3 KB

    Notice the underline character at the end of RegistryKey???

    If you hover your mouse over it, a dropdown list appears offering to add an import for Microsoft.Win32

  6. #6

    Thread Starter
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,842

    Re: get names of all registry keys

    Quote Originally Posted by .paul. View Post
    Name:  23-05-2020_01.11.45.png
Views: 51
Size:  1.3 KB

    Notice the underline character at the end of RegistryKey???

    If you hover your mouse over it, a dropdown list appears offering to add an import for Microsoft.Win32
    I just tried that and of course it worked, I had to re-open vs2019 to try it.
    But I'd swear that didn't happen before, just the 'RegistryKey is not defined' message, I do always look for suggested fixes.


    01.40... Bedtime !


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  7. #7

    Thread Starter
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,842

    Re: get names of all registry keys

    I found the answer... Thank you John McIlhinney

    Code:
        Private Sub Button2_Click() Handles Button2.Click
            Try
                Using CurrentUser = RegistryKey.OpenRemoteBaseKey(RegistryHive.CurrentUser, ""),
                      key = CurrentUser.OpenSubKey("SOFTWARE")
                    For Each subKeyName In key.GetSubKeyNames()
                        If subKeyName IsNot Nothing Then ListBox1.Items.Add(subKeyName)
                    Next
                End Using
            Catch ex As Exception
                Label1.Text = ex.ToString()
            End Try
        End Sub
    Poppa
    Along with the sunshine there has to be a little rain sometime.

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