HOW TO:枚举网络邻居的计算机及其共享文件夹
2024-07-21 02:15:54
供稿:网友
关键引用空间:system.directoryservices,system.management
说明:form上有一个treeview1,button1
代码如下:
private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click
private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click
getnetcomputernameandsharefolder()
end sub
private sub getnetcomputernameandsharefolder()
dim n as treenode = addnode("工作组或域")
dim root as directoryentry = new directoryentry("winnt:")
for each domain as directoryentry in root.children
'枚举工作组或域
dim n1 as treenode = addnode(n, domain.name)
for each computer as directoryentry in domain.children
'枚举指定工作组或域的计算机
if computer.schemaclassname.equals("computer") then
dim n2 as treenode = addnode(n1, computer.name)
'枚举指定计算机的共享文件夹
dim o as new managementobject
o.scope = new managementscope(string.format("//{0}/root/cimv2", computer.name))
dim searcher as managementobjectsearcher = new managementobjectsearcher("select * from win32_share")
searcher.scope = o.scope
for each share as managementobject in searcher.get()
addnode(n2, share.getpropertyvalue("name").tostring)
next
end if
next
next
end sub
private function addnode(byval text as string) as treenode
return me.treeview1.nodes.add(text)
end function
private function addnode(byval node as treenode, byval text as string) as treenode
return node.nodes.add(text)
end function