1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
Imports System.DirectoryServices
Imports System.DirectoryServices.ActiveDirectory
Public Function GetUserMemberOf(ByVal domain As String, ByVal username As String, ByVal password As String, Optional ByRef exeption As Exception = Nothing) As Collections.Generic.List(Of String)
Dim searcher As DirectorySearcher = Nothing
Dim colEntry As New Collections.Generic.List(Of String)
Try
searcher = New DirectorySearcher(New DirectoryEntry("LDAP://" & domain, username, password))
searcher.Filter = String.Concat("(&(objectClass=User) (sAMAccountName=", username, "))")
searcher.PropertiesToLoad.Add("MemberOf")
Dim result As SearchResult = searcher.FindOne
For i As Integer = 0 To result.Properties("MemberOf").Count - 1
Dim sProp As String = result.Properties("MemberOf")(i)
colEntry.Add(sProp.Substring(3, sProp.IndexOf(",") - 3))
Next
Catch ex As Exception
exeption = ex
Finally
searcher.Dispose()
End Try
Return colEntry
End Function
|