Enumerate registry keys, subkeys, and values VB.net.
StdRegProv class
The StdRegProv class contains methods that manipulate system registry keys and values. StdRegProv is preinstalled in the WMI namespaces root\default and root\cimv2.
Syntax
[dynamic, provider("RegProv"), AMENDMENT]
class StdRegProv
{
};
Members
The StdRegProv class has these types of members:
Methods
The StdRegProv class has these methods.
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