'Sometimes it is necessary to scan the registry of the remote computer to determine the existence of some key-value items, or to modify them
'RegistryKey, Registry, and RegistryHive under the Microsoft.Win32 namespace in .NET are used to operate the registry
'|______ 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) 'Add the computer name to the TreeView
treeV.Nodes.Add(k.Name)
Dim s As String
For Each s In k.GetSubKeyNames 'Get the subkey name
treeN.Nodes.Add(s)
subkey = k.OpenSubKey(s)
OpenKeys(subkey) 'Open subkeys/keys
Next
treeV.Nodes.Add(treeN)
End Function
Sub OpenKeys(ByVal Key As Microsoft.Win32.RegistryKey)
'k.SubKeyCount' gets the number of subkeys
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 'Get the subkey name
treeN.Nodes.Add(s)
Try
SubKey = Key.OpenSubKey(s, False)
Me.Text = s
If s Like "*microsoft*" Or s Like "*wgscd*" Then 'Add search termsThen 'Add search terms
'ADD YOR CODE....
MsgBox(s)
End If
OpenKeys(SubKey)
Catch ex As Exception
End Try
Next
treeV.Nodes.Add(treeN) 'Add the registry key to the TreeView as a subkey
End If
End Sub
Sub dome()
OpenRemoteRegister(Microsoft.Win32.RegistryHive.CurrentUser, Net.Dns.GetHostByName("wgscd").HostName) 'Scan the CurrentUser item
'"wgscd" is the name of the remote computer you want to scan. Note that the premise is that you have the corresponding permissions for "remote computer"!
'OpenRemoteRegister(Microsoft.Win32.RegistryHive.LocalMachine, Net.Dns.GetHostByName("wgscd").HostName)'Scan LocalMachine entries
' OpenRemoteRegister(Microsoft.Win32.RegistryHive.Users, Net.Dns.GetHostByName("wgscd").HostName) 'Scan Users items
' OpenRemoteRegister(Microsoft.Win32.RegistryHive.ClassesRoot, Net.Dns.GetHostByName("wgscd").HostName) 'Scan ClassesRoot items
'OpenRemoteRegister(Microsoft.Win32.RegistryHive.CurrentConfig, Net.Dns.GetHostByName("wgscd").HostName) 'Scan CurrentConfig items
'OpenRemoteRegister(Microsoft.Win32.RegistryHive.DynData, Net.Dns.GetHostByName("wgscd").HostName) 'Scan DynData items
End Sub
Sub ScanRemoteRegistry()
Dim Mythread As New Threading.Thread(AddressOf dome)
Mythread.Start()
End Sub
Sub AddTreeViewToForm() 'Add TreeView to Formss
With treeV
.Width = 400
.Height = 500
End With
Me.Controls.Add(treeV)
End Sub
call:
ScanRemoteRegistry()