Solved

Recursive search Through the registry

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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