获取局域网中所有PC的列表

时间:2019-08-20 14:24:05

标签: vb.net lan

以下代码间歇性地工作。为什么呢?有时结果为空白,没有任何错误。

    Imports System.DirectoryServices
    Public Class Form1

        Private Sub Button_Click(sender As System.Object, e As System.EventArgs) Handles Button.Click
            Dim result As String = ""            
            Dim domainEntry As DirectoryEntry = New DirectoryEntry("WinNT://CA")'CA is the workgroup
            domainEntry.Children.SchemaFilter.Add("Computer")

            For Each computer As DirectoryEntry In domainEntry.Children
                result = result & computer.Name & Environment.NewLine
            Next
            MsgBox(result)

        End Sub
End class

1 个答案:

答案 0 :(得分:0)

Windows工作组是点对点排列的,没有中央服务器来控制谁在工作组中。因此,列出工作组中所有计算机的唯一方法是联系网络中的每台计算机,并检查它们是否属于工作组。这意味着每台计算机都必须打开电源并连接到同一LAN。

我的猜测是,某些计算机在运行时处于脱机状态,这是由于其他原因导致在运行时无法联系它们。


旧答案:

我对使用WinNT提供程序并不十分熟悉,但是请查看使用LDAP是否会得到不同的结果。这将查找域中的所有计算机(我假设“ CA”是您的域的名称):

Dockerfile.A