可以将路径指定为"WinNT:"枚举出一个局域网内所有的域,如下列代码所示: DirectoryEntry objSpace = new DirectoryEntry("WinNT:");
foreach(DirectoryEntry domain in objSpace.Children)
System.Diagnostics.Debug.WriteLine(domain.Name); 如果要枚举一个组中的所有成员,首先要激活其Members成员,并查询(映射到)他的IEnumerable接口。然后遍历其中每一个元素,生成相应的入口对象并输出。如下列代码所示: string domainName = "Domain";
string groupName = "Group";
DirectoryEntry group = new DirectoryEntry("WinNT://" + domainName + "/" + groupName + ",group"); foreach(Object member in (IEnumerable)group.Invoke("Members"))
{
DirectoryEntry dirmem = new DirectoryEntry(member);
Console.WriteLine(dirmem.Name);
}
foreach(DirectoryEntry domain in objSpace.Children)
System.Diagnostics.Debug.WriteLine(domain.Name); 如果要枚举一个组中的所有成员,首先要激活其Members成员,并查询(映射到)他的IEnumerable接口。然后遍历其中每一个元素,生成相应的入口对象并输出。如下列代码所示: string domainName = "Domain";
string groupName = "Group";
DirectoryEntry group = new DirectoryEntry("WinNT://" + domainName + "/" + groupName + ",group"); foreach(Object member in (IEnumerable)group.Invoke("Members"))
{
DirectoryEntry dirmem = new DirectoryEntry(member);
Console.WriteLine(dirmem.Name);
}
解决方案 »
- [求助]如何用C#的System.Threading类实现并行问题呢?
- TreeView 得到当前选中子节点上一级节点属性
- 怎样制作qq tab
- 请问如何让单行TextBox中的文本自右向左匀速滚动?请教高手!
- 100分,水晶报表问题:C#调用水晶报表参数值过大时发生错误
- 谁有XTraGrid中文使用说明? 急
- MYSQL还原乱码问题,再补发一帖,解决两贴200分一起结
- 请问实现这样一个功能用什么解决方案比较好?
- 怎样才能知道对象又被处置过了(object.dispose())
- 请大家评评此书!
- help:我用streamwrite写入一个ini文件,但再取出来中文为何是乱码?
- C#初学者的问题,谢谢指教
' GetAllGroups
' WriteBy:Singhua
' Description: get one domain's all groups
' 得到一個網域下所有的群組
' Arguments: attributes of the object:
' DcServer - the server keep the groups
' return: an array of all the groups
' modify history:
'======================================================================================
Function GetAllGroups(ByVal DcServer As String) As Object
DcServer = Trim(DcServer)
Dim myDomain
Dim group
Dim str As String DcServer = "WinNT://" & DcServer myDomain = GetObject(DcServer) Dim filter(0), oGroups() As Object
filter(0) = "group" myDomain.Filter = filter 'if filter = {"group","user"} then show all the user
For Each group In myDomain
str = str & "^" & group.Name
Next str = Right(str, str.Length - 1)
oGroups = Split(str, "^")
System.Array.Sort(oGroups) GetAllGroups = oGroups
End Function '======================================================================================
' GetAllUserInGroup
' WriteBy:Singhua
' Description: get all users in one group
' 得到一個群組下所有的人員
' Arguments: attributes of the object:
' DcServer - the server keep the groups
' GroupName - the group name your want to get user
' return: an array of all users in the group
' modify history:
'======================================================================================
Function GetAllUserInGroup(ByVal DcServer As String, ByVal GroupName As String, _
ByVal Domain As String) As Object
DcServer = Trim(DcServer)
GroupName = Trim(GroupName)
Domain = LCase(Trim(Domain)) Dim myGroup
Dim user
Dim str As String
Dim Members, oUsers() As Object
Dim i, m As Integer DcServer = "WinNT://" & DcServer & "/" & GroupName & ",group"
Try
myGroup = GetObject(DcServer)
Catch ex As Exception
GetAllUserInGroup = Nothing
Exit Function
End Try Members = myGroup.Members
For Each user In Members
str = str & "^" & LCase(user.Name)
Next str = Right(str, str.Length - 1)
oUsers = Split(str, "^")
System.Array.Sort(oUsers) m = UBound(oUsers)
For i = 0 To m
oUsers(i) = Domain & "\" & oUsers(i)
Next GetAllUserInGroup = oUsers
End Function
參考一下,MSDN中有例子
希望可以幫到你