Pomocí následujících metod můžete zjistit skupiny a členy skupin NA MÍSTNÍM POČÍTAČI. Pokud byste to chtěl zjišťovat ze skutečného Active Directory, bylo by to poměrně komplikovanější...
Imports System.Collections
Imports System.DirectoryServices
...
Public Function GetGroups() As List(Of String)
Dim groups As New List(Of String)
Using computer As DirectoryEntry = New DirectoryEntry("WinNT://" & Environment.MachineName & ",computer")
computer.Children.SchemaFilter.Add("group")
For Each group As DirectoryEntry In computer.Children
groups.Add(group.Name)
Next
End Using
Return groups
End Function
Public Function GetUsers(ByVal groupName As String) As List(Of String)
Dim users As New List(Of String)
Using computer As DirectoryEntry = New DirectoryEntry("WinNT://" & Environment.MachineName & ",computer")
Using group As DirectoryEntry = computer.Children.Find(groupName, "group")
If group IsNot Nothing Then
Dim members As Object = group.Invoke("Members", Nothing)
For Each member As Object In DirectCast(members, IEnumerable)
Dim user As New DirectoryEntry(member)
users.Add(user.Name)
Next
End If
End Using
End Using
Return users
End Function
|