본문 바로가기
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


'VB.net' 카테고리의 다른 글

PC 1시간뒤 자동 종료되게 하기  (0) 2018.05.11
폴더, 파일 존재여부 확인  (0) 2018.05.03
C# > VB.NET 변환기  (0) 2018.04.24
롤링 ListBox  (0) 2018.04.16
숫자 올림, 반올림, 버림  (0) 2018.04.11