我想让所有的组“安全组”在活动食堂中可用。
有什么想法吗?
谢谢,
发布于 2011-09-06 17:11:59
由于您使用的是.NET 3.5或更高版本,因此可以使用PrincipalSearcher和“按示例查询”主体来执行搜索:
// create your domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// define a "query-by-example" principal - here, we search for a GroupPrincipal
// with the security group flag set
GroupPrincipal qbeGroup = new GroupPrincipal(ctx);
qbeGroup.IsSecurityGroup = true;
// create your principal searcher passing in the QBE principal
PrincipalSearcher srch = new PrincipalSearcher(qbeGroup);
// find all matches
foreach(var found in srch.FindAll())
{
// do whatever here - "found" is of type "Principal" - it could be user, group, computer.....
}如果您还没有,请阅读MSDN文章Managing Directory Security Principals in the .NET Framework 3.5,它很好地展示了如何充分利用System.DirectoryServices.AccountManagement中的新特性
发布于 2015-05-11 17:24:47
试试这条路
DirectoryEntry ent1 = new DirectoryEntry("LDAP://" + _path,
"adminUser", "***********");
DirectorySearcher dSearch = new DirectorySearcher(ent1);
dSearch.Filter = "(&(objectClass=group))";
dSearch.SearchScope = SearchScope.Subtree;
SearchResultCollection results = dSearch.FindAll();
List<string> groupNames = new List<string>();
for (int i = 0; i < results.Count; i++)
{
DirectoryEntry de = results[i].GetDirectoryEntry();
groupNames.Add(de.Name.Replace("CN=", ""));
}它正在为我工作:)
https://stackoverflow.com/questions/7317205
复制相似问题