'有時候需要掃描遠程計算機的注冊表,判斷一些鍵值項的存在與否,或者修改他們
'.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()