程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> .NET掃描遠程計算機注冊表

.NET掃描遠程計算機注冊表

編輯:.NET實例教程

   '有時候需要掃描遠程計算機的注冊表,判斷一些鍵值項的存在與否,或者修改他們
    '.Net 裡的Microsoft.Win32命名空間下的RegistryKey ,Registry,RegistryHive就是用來操作注冊表的

    '|______  ScanRemoteRegister ___________|
    '|  Coypright wgscd (c)2005             |
    '|  QQ:153964481 E-mail:[email protected]   |
    '|  Blog:http://blog.csdn.Net/wgsnet    |
    '|______________________________________|

    Dim treeV As New TreeVIEw
    Dim SubNode As New TreeNode
    Dim treeN As New TreeNode
    Function OpenRemoteRegister(ByVal RemoteBaseKey As String, ByVal ComputerName As String) As String
        Dim subkey As Microsoft.Win32.RegistryKey
        Dim k As Microsoft.Win32.RegistryKey = Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(RemoteBaseKey, Net.Dns.GetHostByName(ComputerName).HostName)
        treeV.Nodes.Add(Net.Dns.GetHostByName(ComputerName).HostName) '將計算機名添加到TreeVIEw
        treeV.Nodes.Add(k.Name)
        Dim s As String
        For Each s In k.GetSubKeyNames '得到子鍵項Name
            treeN.Nodes.Add(s)
            subkey = k.OpenSubKey(s)
            OpenKeys(subkey) '打開子項/鍵
        Next
        treeV.Nodes.Add(treeN)
    End Function
    Sub OpenKeys(ByVal Key As Microsoft.Win32.RegistryKey)
        'k.SubKeyCount'得到子鍵項數
        Dim s As String
        Dim SubKey As Microsoft.Win32.RegistryKey
        treeN.Nodes.Add(Key.Name)
        If Key.GetSubKeyNames.Length > 0 Then
            For Each s In Key.GetSubKeyNames '得到子鍵項Name
                treeN.Nodes.Add(s)
                Try
                    SubKey = Key.OpenSubKey(s, False)

                    Me.Text = s If s Like "*microsoft*" Or s Like "*wgscd*" Then  '加如搜索條件Then '加如搜索條件
                        'ADD YOR CODE ....
                        MsgBox(s)
                    End If
                    OpenKeys(SubKey)
                Catch ex As Exception
                End Try

            Next
            treeV.Nodes.Add(treeN) '將注冊表項以子項添加到TreeVIEw

        End If
    End Sub
    Sub dome()
        OpenRemoteRegister(Microsoft.Win32.RegistryHive.CurrentUser, Net.Dns.GetHostByName("wgscd").HostName) '掃描CurrentUser項
        '“wgscd”是你要掃描的遠程計算機名,注意,前提是你對“遠程計算機”有相應的權限!
        'OpenRemoteRegister(Microsoft.Win32.RegistryHive.LocalMachine, Net.Dns.GetHostByName("wgscd").HostName)’掃描LocalMachine項
        ' OpenRemoteRegister(Microsoft.Win32.RegistryHive.Users, Net.Dns.GetHostByName("wgscd").HostName) '掃描Users項
        ' OpenRemoteRegister(Microsoft.Win32.RegistryHive.ClassesRoot, Net.Dns.GetHostByName("wgscd").HostName) '掃描ClassesRoot項
        'OpenRemoteRegister(Microsoft.Win32.RegistryHive.CurrentConfig, Net.Dns.GetHostByName("wgscd").HostName) '掃描CurrentConfig項
        'OpenRemoteRegister(Microsoft.Win32.RegistryHive.DynData, Net.Dns.GetHostByName("wgscd").HostName) '掃描DynData項
    End Sub
    Sub ScanRemoteRegistry()
        Dim Mythread As New Threading.Thread(AddressOf dome)
        Mythread.Start()
    End Sub
    Sub AddTreeViewToForm() '將TreeVIEw添加到Formss上 
        With treeV
            .Width = 400
            .Height = 500
        End With
     &
nbsp;  Me.Controls.Add(treeV)
    End Sub

調用:

        ScanRemoteRegistry()


  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved