Solved

Recursive search Through the registry

Posted on 2004-09-22
7
2,760 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now