DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   vb.net 08 Reading data from multiple reg keys (http://www.daniweb.com/forums/thread166523.html)

Comatose Jan 7th, 2009 10:37 am
Re: vb.net 08 Reading data from multiple reg keys
 
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...

Ramy Mahrous Jan 7th, 2009 10:40 am
Re: vb.net 08 Reading data from multiple reg keys
 
Try Comatose's code, and tell what you get?

smelf1 Jan 7th, 2009 10:49 am
Re: vb.net 08 Reading data from multiple reg keys
 
okay that code returns no errors but how do i display the display names it finds in a combo or text box?

Ramy Mahrous Jan 7th, 2009 11:34 am
Re: vb.net 08 Reading data from multiple reg keys
 
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

smelf1 Jan 7th, 2009 11:49 am
Re: vb.net 08 Reading data from multiple reg keys
 
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

Comatose Jan 7th, 2009 12:26 pm
Re: vb.net 08 Reading data from multiple reg keys
 
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

Ramy Mahrous Jan 7th, 2009 12:31 pm
Re: vb.net 08 Reading data from multiple reg keys
 
I know Comatose, but it was my last chance to get him solve his problem!!!

Comatose Jan 7th, 2009 12:36 pm
Re: vb.net 08 Reading data from multiple reg keys
 
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 ;)

smelf1 Jan 7th, 2009 12:46 pm
Re: vb.net 08 Reading data from multiple reg keys
 
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.

Comatose Jan 7th, 2009 1:44 pm
Re: vb.net 08 Reading data from multiple reg keys
 
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


All times are GMT -4. The time now is 2:59 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC