【发布时间】:2012-09-26 10:12:55
【问题描述】:
我正在尝试围绕 LINQ 进行研究,以便弄清楚如何查询 DirectoryEntry。目前,我正在尝试在 C# 中编写一些代码,该代码将采用一个字符串变量,并根据该字符串给出一个组内的成员列表。
以下是我迄今为止设法弄清楚的内容
public static string[] GetAllUsersInGroup(string groupname)
{
var names = new List<string>();
var path = string.Format("WinNT://{0},computer", Environment.MachineName);
var computerEntry = new DirectoryEntry(path);
if (computerEntry != null)
{
using (computerEntry)
{
var menberNames = from DirectoryEntry childEntry
in computerEntry.Children.Find("testgroup", "group")
where childEntry.SchemaClassName == "User"
select childEntry.Name;
foreach (var name in memberNames)
{
names.Add(name);
}
}
}
return names.ToArray();
}
这个问题是我不能在 where 语句中使用Children.Find()。
虽然我想知道如何正确执行此操作,但我真的希望能够弄清楚这一点,因为我还需要做其他查询。因此,如果有人知道找到此信息的任何好的来源,请告诉我
【问题讨论】:
-
这里有什么问题?什么不工作?
-
@PaulAlanTaylor 我不能使用 Children.Find() 是 where 因为它不是布尔值,即如果我有东西我
where childEntry.SchemaClassName == "User"这将有助于返回计算机中的所有用户跨度>
标签: linq directoryentry