【问题标题】:List of computers in Active Directory that are onlineActive Directory 中在线的计算机列表
【发布时间】:2010-09-23 13:04:03
【问题描述】:

我正在使用这个 sn-p 代码来输出我网络上所有计算机的列表(语言是 jscript.net,但它只是对 C# 的一个小操作)。

    var parentEntry = new DirectoryEntry();

    parentEntry.Path = "WinNT:";
    for(var childEntry in parentEntry.Children) {
        if(childEntry.SchemaClassName == "Domain") {
            var parentDomain = new TreeNode(childEntry.Name); 
            this.treeView1.Nodes.Add(parentDomain);

            var subChildEntry : DirectoryEntry;
            var subParentEntry = new DirectoryEntry();
            subParentEntry.Path = "WinNT://" + childEntry.Name;
            for(subChildEntry in subParentEntry.Children) {
                var newNode1 = new TreeNode(subChildEntry.Name);
                if(subChildEntry.SchemaClassName == "Computer") {
                    parentDomain.Nodes.Add(newNode1);
                }
            }
        }

    }

我有两个问题:

1) 非常慢。大约有 100 台计算机显示,加载大约需要 1 分钟。

2) 我只想获取当前在线的计算机列表。

这是可以做到的,因为我见过其他程序这样做,而且它们的速度要快得多,而且它们只能在线显示那些。

我错过了什么吗?

【问题讨论】:

    标签: c# active-directory ldap jscript.net


    【解决方案1】:

    我知道它有点老了,但对其他人来说...这个 sn-p 将在 2-3 秒内使用 AD 从域中返回 760 个计算机名称....一个显着的改进....享受!

        Friend Shared Function DomainComputers() As Generic.List(Of String)
    
        ' Add a Reference to System.DirectoryServices
    
        Dim Result As New Generic.List(Of String)
    
        Dim ComputerName As String = Nothing
        Dim SRC As SearchResultCollection = Nothing
        Dim Searcher As DirectorySearcher = Nothing
    
        Try
    
            Searcher = New DirectorySearcher("(objectCategory=computer)", {"Name"})
    
            Searcher.Sort = New SortOption("Name", SortDirection.Ascending)
            Searcher.Tombstone = False
    
            SRC = Searcher.FindAll
    
            For Each Item As SearchResult In SRC
                ComputerName = Item.Properties("Name")(0)
                Result.Add(ComputerName)
            Next
    
        Catch ex As Exception
    
        End Try
    
        Return Result
    
    End Function
    

    【讨论】:

      【解决方案2】:

      我会查看 CodePlex 上的 Linq To Active Directory

      您还必须定义“我的网络”。你的子网?您的组织单位?你的域名?你的森林?

      还要考虑您要查询的 LDAP 服务器在哪里。它是关闭的还是在远程链接的另一端?

      您还认为什么是“在线”?您希望能够 ping 通它吗?您是否希望能够连接到它并执行操作?

      这里有很多事情要考虑。此外,如果您有其他基础架构组件,例如 SCCM/SMS 服务器,则通常可以更快地查询它们,因为所有发现数据都已流入数据仓库。

      【讨论】:

      • 我认为他的意思是:就像 Windows 资源管理器一样。它没有向您显示网络位置,如果您尝试打开并列出共享,将返回以下错误:RPC 服务器不可用...我现在也在寻找...跨度>
      猜你喜欢
      • 1970-01-01
      • 2019-04-21
      • 1970-01-01
      • 1970-01-01
      • 2018-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多