网络VB.Net上的计算机名称

我想列出列表框中的所有连接的网络计算机.有谁知道怎么样?
最佳答案
添加对System.DirectoryServices的引用.

加;

Imports System.DirectoryServices

然后使用;

Private Delegate Sub UpdateDelegate(ByVal s As String)

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Dim t As New Threading.Thread(AddressOf GetNetworkComputers)
    t.IsBackground = True
    t.Start()

End Sub

Private Sub AddListBoxItem(ByVal s As String)
    ListBox1.Items.Add(s)
End Sub

Private Sub GetNetworkComputers()
    Dim alWorkGroups As New ArrayList
    Dim de As New DirectoryEntry

    de.Path = "WinNT:"
    For Each d As DirectoryEntry In de.Children
        If d.SchemaClassName = "Domain" Then alWorkGroups.Add(d.Name)
        d.Dispose()
    Next

    For Each workgroup As String In alWorkGroups

        de.Path = "WinNT://" & workgroup
        For Each d As DirectoryEntry In de.Children

            If d.SchemaClassName = "Computer" Then

                Dim del As UpdateDelegate = AddressOf AddListBoxItem
                Me.Invoke(del, d.Name)

            End If

            d.Dispose()

        Next
    Next
End Sub

转载注明原文:网络VB.Net上的计算机名称 - 代码日志