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

2008-02-22 09:32:10来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

'有时候需要扫描远程计算机的注册表,判断一些键值项的存在与否,或者修改他们
'.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()

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:简单而又复杂的ASP.NET编程模型

下一篇:利用.NET的File控件上传文件的最终解决方案(个人版)