Active Directory 中联机的计算机列表

List of computers in Active Directory that are online(Active Directory 中联机的计算机列表)
本文介绍了Active Directory 中联机的计算机列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using this snippet of code to output a list of all the computers on my network (the language is jscript.net, but it's just a small manipulation of 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 分钟.

1) It is extremely slow. There's about 100 computers showing, and it takes about 1 minute to load.

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

2) I want to get only a list of computers that are currently online.

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

This can be done because I've seen other programs doing it and they are much faster, also they're able to show only the ones online.

我错过了什么吗?

推荐答案

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

I know it's a bit old, but for others...this snippet will return a 760 computer names from a domain using AD within 2-3 seconds....a significant improvement....enjoy!

    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

这篇关于Active Directory 中联机的计算机列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)