Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 哪些ActiveDirectory对象可以包含计算机?_C#_Active Directory_Directoryservices - Fatal编程技术网

C# 哪些ActiveDirectory对象可以包含计算机?

C# 哪些ActiveDirectory对象可以包含计算机?,c#,active-directory,directoryservices,C#,Active Directory,Directoryservices,我需要浏览以选择计算机对象。我发现,有些容器可能包含计算机项,而另一些容器可能包含用户、组策略等。我只想显示包含计算机的容器。因此,我使用此代码检查容器是否包含任何计算机: public static bool CheckContainsComputers(DirectoryEntry entry) { using (DirectorySearcher ds = new DirectorySearcher(entry, "(objectCategory=comput

我需要浏览以选择计算机对象。我发现,有些容器可能包含计算机项,而另一些容器可能包含用户、组策略等。我只想显示包含计算机的容器。因此,我使用此代码检查容器是否包含任何计算机:

public static bool CheckContainsComputers(DirectoryEntry entry)
{
    using (DirectorySearcher ds =
           new DirectorySearcher(entry, "(objectCategory=computer)", new string[0], SearchScope.Subtree))
    {
        ds.Asynchronous = true;
        ds.SizeLimit = 1;
        try
        {
            SearchResult sr = ds.FindOne();
            return (sr == null) ? false : true;
        }
        catch
        {
            return false;
        }
    }
}
问题:

为了减少调用此方法的次数,我想知道-是否可以在不运行的情况下找出是否可以包含计算机

是否可以通过一次对的调用来查找可以拥有计算机和计算机的容器


1.如果您已经拥有directoryEntry,则无需再次搜索它。 我想你想要的是这样的:

if (entry.Properties["objectCategory"].Value.ToString().Contains("Computer"))
return true;
else
return false;
二,。 当然

DirectoryEntry de = new DirectoryEntry("LDAP://myldapserver.com");
DirectorySearcher directorySearcher = new DirectorySearcher(de);
directorySearcher.SearchScope = SearchScope.OneLevel;
directorySearcher.Filter = "(objectCategory=computer)";
SearchResultCollection srCollection = directorySearcher.FindAll();

第一个假设包含对事实的验证,即条目是一台计算机。问题中描述了第二个问题。所以,这不是一个答案。