Question

I already figured out how to get the registrykeys, what I am now stucking at is how to get registryvalues of a specific path?

Private Sub ListRegistryKeys(ByVal RegistryHive As String, ByVal RegistryPath As String)
    Dim key As Microsoft.Win32.RegistryKey
    Select Case RegistryHive
        Case "HKEY_LOCAL_MACHINE" : key = My.Computer.Registry.LocalMachine.OpenSubKey(RegistryPath)
        Case "HKEY_CURRENT_USER" : key = My.Computer.Registry.CurrentUser.OpenSubKey(RegistryPath)
        Case "HKEY_CLASSES_ROOT" : key = My.Computer.Registry.ClassesRoot.OpenSubKey(RegistryPath)
        Case "HKEY_CURRENT_CONFIG" : key = My.Computer.Registry.CurrentConfig.OpenSubKey(RegistryPath)
        Case "HKEY_USERS" : key = My.Computer.Registry.Users.OpenSubKey(RegistryPath)
        Case Else
            Throw New Exception("Unknow Registry Hive.")
    End Select
    For Each subkey In key.GetSubKeyNames
        ListView2.Items.Add(subkey.ToString)
    Next
End Sub

Thats what I use to get the registrykeys. Now I like to get the same one for registryvalues, by specifying the Registryhive and the path to the key in the header. I want the 3 properties of the registryvalues found.

Registry Values in Regedit

That means

1) Valuename 2) Valuetype 3) Data of the value

How can I modify the sample from above to accomplish that?

Was it helpful?

Solution

If I am understanding you correctly, You'd like to get the values in the path and write them out in a list view, similar to the screenshot you took of the registry editor. You can modify the sample code you provided as follows:

Private Sub ListRegistryKeys(ByVal RegistryHive As String, ByVal RegistryPath As String)
    Dim key As Microsoft.Win32.RegistryKey
   
    Select Case RegistryHive
        Case "HKEY_LOCAL_MACHINE" : key = My.Computer.Registry.LocalMachine.OpenSubKey(RegistryPath)
        Case "HKEY_CURRENT_USER" : key = My.Computer.Registry.CurrentUser.OpenSubKey(RegistryPath)
        Case "HKEY_CLASSES_ROOT" : key = My.Computer.Registry.ClassesRoot.OpenSubKey(RegistryPath)
        Case "HKEY_CURRENT_CONFIG" : key = My.Computer.Registry.CurrentConfig.OpenSubKey(RegistryPath)
        Case "HKEY_USERS" : key = My.Computer.Registry.Users.OpenSubKey(RegistryPath)
        Case Else
            Throw New Exception("Unknow Registry Hive.")
    End Select

    key.OpenSubKey(RegistryPath)

    For Each v In key.GetValueNames()
        Dim lvItem As ListViewItem = ListView2.Items.Add(v)
        lvItem.SubItems.Add(subKey.GetValue(v))
        lvItem.SubItems.Add(subKey.GetValueKind(v).ToString())
    Next

End Sub

I call the OpenSubKey method of the RegistryKey containing the selected hive using the path provided. Then I loop through all of the values, creating a list view item for each value. The sub-items contain the value and type respectively.

Please note that this is not complete. You will want to check that the registry path exists or trap an error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top