Solved

Recursive search Through the registry

Posted on 2004-09-22
7
2,795 Views
Last Modified: 2009-12-16
I am trying to search for a particular value in the registry. How can a have vb.net recursively search values through the registry?

Thanks!
0
Comment
Question by:joshuaanderson
  • 3
7 Comments
 
LVL 18

Expert Comment

by:armoghan
ID: 12131059
This is a code in VB
http://www.freevbcode.com/ShowCode.Asp?ID=3175

can be converted to VB.NET
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12131065
0
 

Author Comment

by:joshuaanderson
ID: 12134054
Well, I figured it out. I appreciate comments. Here is real VB.net code that worked to recursively find a value in the registry.
I have not seen any VB.net code like this. So hopefully this will help out others.

Imports System
Imports Microsoft.Win32
Imports System.Threading

Public Class Form1
    Inherits System.Windows.Forms.Form
    Public Shared ProcessThread As Thread
    Dim Path As String = "System\\ControlSet001\\Control\\Network\\"
    Dim SearchStr As String = "Name = Local Area Connection"

  Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ProcessThread = New Thread(AddressOf SearchThread)
        ProcessThread.Start()
    End Sub

    Sub SearchThread()
        Search(Path, SearchStr)
    End Sub

    Public Sub Search(ByVal Path As String, ByVal SearchStr As String)
        Dim ParentKey As RegistryKey = Registry.LocalMachine.OpenSubKey(Path, True)
        ' Loop through values in the subkey
        For Each valueName As String In ParentKey.GetValueNames()
            On Error Resume Next
            'Create String to Compare against
            Dim CurStr As String = valueName + " = " + ParentKey.GetValue(valueName)
            ListBox1.Items.Insert(0, valueName + " = " + ParentKey.GetValue(valueName))
            If CurStr = SearchStr Then
                MsgBox(CurStr)
                CurStr = ""
            End If
        Next
        'if there are sub keys loop through and be recursive
        If ParentKey.SubKeyCount > 0 Then
            For Each subKeyName As String In ParentKey.GetSubKeyNames()
                ListBox1.Items.Insert(0, "")
                ListBox1.Items.Insert(0, Path + subKeyName) ' Writing the Keyname
                'This is what makes me recursive!
                Dim Thispath As String = Path + subKeyName + "\\"
                Search(Thispath, SearchStr)
            Next
        End If

    End Sub

End Class
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12140183
its nice to hear that you got the solution
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 12393679
PAQed, with points refunded (500)

Computer101
E-E Admin
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question