Hi,

In the reg key below there can be 50 different keys, how can i read through each one and get its display name and then show those display names in a lsitbox or combo box.

hkey_local_machine\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

I am using the code below to get the data in that single key but how do i get all data in display name in each of the multiple keys located in the key folder above

Imports System
Imports Microsoft.Win32

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myCPUDescription As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0", "ProcessorNameString", "No CPU Found").ToString.Trim
        
 ComboBox1.Items.Add(myCPUDescription)

end sub

Put your key in array Dim key As String(numberOfKeys) then loop and once you get value put it into ComboBox or any control you present data into

Dim registrykeys(5) As String
'fill your keys
        For Each key As String In registrykeys
            ComboBox1.Items.Add(My.Computer.Registry.GetValue(key, "property", "default"))
        Next

Your array may be 2D to maintain the property of keys

Put your key in array Dim key As String(numberOfKeys) then loop and once you get value put it into ComboBox or any control you present data into

Dim registrykeys(5) As String
'fill your keys
        For Each key As String In registrykeys
            ComboBox1.Items.Add(My.Computer.Registry.GetValue(key, "property", "default"))
        Next

Your array may be 2D to maintain the property of keys

Hi thanks for the reply.

I am new to vb.net so bear with me : ).

Now in that part of the reg i am looking the keys can be different depending on the installed programs.

So i cannot just add the exact key to read.

Put your key in array
Dim key As String(numberOfKeys)

sorry I've mistake in this instead Dim Keys(numberOfKeys) As string

Give me the keys you want to get and it's properties in that way
Exmaple
Key: HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0
Property: ProcessorStringName

Don't worry, just show me you want to learn

Give me the keys you want to get and it's properties in that way
Exmaple
Key: HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0
Property: ProcessorStringName

Don't worry, just show me you want to learn

No probs thanks,

The keys are all located in hkey_local_machine\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall its where the registry stores all the installed programs.

I want to open each key it finds under hkey_local_machine\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall and display what is in DisplayName in a combobox or text box.

So on my pc i have a program called casecatalyst and its key is under
hkey_local_machine\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\caseCatalyst4 and in here i am after DisplayName which is Case Catalyst.

So if i only have casecatalyst and say adobe installed the only keys in hkey_local_machine\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall will be \casecatalyst4 and \adobe.

So i assume i need to be able to open uninstall\ read each key and populate their display names into a combo or text box.

See i need to find all currently installed programs on a pc

I found something similar in c#

( static void GetInstalled()
{
      string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
      using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
      {
            foreach (string skName in rk.GetSubKeyNames())
            {
                  using (RegistryKey sk = rk.OpenSubKey(skName))
                  {
                        Console.WriteLine(sk.GetValue("DisplayName"));
                  }
            }
      }
})

can this be changed into .net?

I'm newer to vb.net so the others might change this a bit

Private Shared Sub GetInstalled()
         Dim uninstallKey As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
         Using rk As RegistryKey = Registry.LocalMachine.OpenSubKey(uninstallKey)
             For Each skName As String In rk.GetSubKeyNames()
                 Using sk As RegistryKey = rk.OpenSubKey(skName)
                     Console.WriteLine(sk.GetValue("DisplayName"))
                 End Using
             Next
         End Using
     End Sub
Comments
Perfect Code Port

Yes, It could be, understand the C# code, and if you fail to convert any line of code to VB.NET, drop a reply soon.

okay i got this now but it returns nothing

Dim uninstallKey As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
        Dim rk As RegistryKey
        rk = Registry.LocalMachine.OpenSubKey(uninstallKey)
        For Each key As String In rk.GetSubKeyNames()
            Using sk As RegistryKey = rk.OpenSubKey(key)
                Console.WriteLine(sk.GetValue("DisplayName"))
            End Using
        Next
    End Sub

C# IS .net. It's just a C style usage of it.

Public Function GetInstalled()
        Dim uninstallKey As String
        Dim rk As RegistryKey
        Dim sk As RegistryKey
        Dim skName As String
        Dim sublist As New ArrayList

        uninstallKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

        rk = Registry.LocalMachine.OpenSubKey(uninstallKey, True)

        For Each skName In rk.GetSubKeyNames()
            sk = rk.OpenSubKey(skName)
            sublist.Add(sk.GetValue("DisplayName"))
        Next skName

        Return sublist
    End Function

EDIT: Sorry, Didn't Refresh The Page Before Posting...

okay that code returns no errors but how do i display the display names it finds in a combo or text box?

Drag a comboBox and drop it into your form
Edit Comatose's code

For Each skName In rk.GetSubKeyNames()            
sk = rk.OpenSubKey(skName)            
comboBox1.Items.Add(sk.GetValue("DisplayName"))        
Next skName

okay, but when i run the code nothing gets returned in the box.

could it be the displayname part as if you go to the registry and pick a sub key, you will see displayname. When you click on display name the key is shown but its the 2nd part under value data i need.

as if i want a particular key for the processor i use

Dim myCPUDescription As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0", "ProcessorNameString", "No CPU Found").ToString.Trim

and that returns the value data under the key

You shouldn't modify the function. The concept of a function, is that you shouldn't make them interact with the form. The idea of a function is that a function can be modular.... what if in the future, you decide to change it from a combobox, to a listbox... or save it to a file. Then you have to modify the function that actually GETS the display names of the registry keys. The purpose of a function is abstraction.... what this function does, is get the list of items in the registry (their display values) and returns them to the calling procedure. So for example, if you have a button, you would do:

dim something as new arraylist
something = GetInstalled()
for I = 0 to something.count 
     msgbox something(i)
next I

It might have to be for I = 0 to something.count -1

I know why you did it, and were absolutely right... I just wanted to make the distinction for him, so that he understands the concepts. I would have suggested the same code mod you did ;)

ah right so the function is left alone so if i add a button i would now need to call that function from the code under the button.

Right, it returns an arraylist. So you would call it from the button, then assign the return value to an arraylist, and loop through it.

dim something as new arraylist
something = GetInstalled()
for I = 0 to something.count 
     msgbox something(i)
next I

got it working, i have a button and combobox in the form.

I call the getinstalled function from the button and it populates the combo box with all the installed programs.

So thanks for the help.

This question has already been answered. Start a new discussion instead.