VB.net
레지스트리 하위키 값 검색
by 호야호잇
2018. 4. 27.
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