joshuaanderson
asked on
Recursive search Through the registry
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!
Thanks!
thsi is how you read a single entry in registry
https://www.experts-exchange.com/questions/20964736/Reading-registry-keys.html
https://www.experts-exchange.com/questions/20964736/Reading-registry-keys.html
ASKER
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\\Co ntrol\\Net work\\"
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.Open SubKey(Pat h, 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(valueNa me)
ListBox1.Items.Insert(0, valueName + " = " + ParentKey.GetValue(valueNa me))
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
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\\Co
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.Open
' 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(valueNa
ListBox1.Items.Insert(0, valueName + " = " + ParentKey.GetValue(valueNa
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
its nice to hear that you got the solution
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.freevbcode.com/ShowCode.Asp?ID=3175
can be converted to VB.NET