HOW TO:枚舉網(wǎng)絡(luò)鄰居的計算機(jī)及其共享文件夾
2024-07-21 02:15:54
供稿:網(wǎng)友
關(guān)鍵引用空間: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
'枚舉指定工作組或域的計算機(jī)
if computer.schemaclassname.equals("computer") then
dim n2 as treenode = addnode(n1, computer.name)
'枚舉指定計算機(jī)的共享文件夾
dim o as new managementobject
o.scope = new managementscope(string.format("http://{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