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