WEB开发网
开发学院WEB开发ASP.NET .NET扫描远程计算机注册表 阅读

.NET扫描远程计算机注册表

 2006-01-10 17:04:56 来源:WEB开发网   
核心提示: '有时候需要扫描远程计算机的注册表,判断一些键值项的存在与否,.NET扫描远程计算机注册表,或者修改他们 '.NET 里的Microsoft.Win32命名空间下的RegistryKey ,Registry,RegistryHive就是用来操作注册表的 '|______ ScanRem

   '有时候需要扫描远程计算机的注册表,判断一些键值项的存在与否,或者修改他们
   '.NET 里的Microsoft.Win32命名空间下的RegistryKey ,Registry,RegistryHive就是用来操作注册表的

   '|______  ScanRemoteRegister ___________|
   '|  CoyPRight wgscd (c)2005       |
   '|  QQ:153964481 E-mail:wgscd@126.com  |
   '|  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
     Me.Controls.Add(treeV)
   End Sub

调用:

   ScanRemoteRegistry()

Tags:NET 扫描 远程

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接