Please help! The code below generates an "invalid username or password" error when running. I have to be close....using RootDSE instead of "LDAP://ab.cd.com" throws the same error. I am hardcoding username & password, etc for basic testing.
Also, my end goal is to list all groups a user member is a member of & dump then in a textbox. Please show me what I'm doing wrong! Thanks!
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim de As New DirectoryEntry("LDAP://ab.cd.com", "ab/username", "password", AuthenticationTypes.Secure)
Dim ds As New DirectorySearcher(de)
ds.SearchScope = SearchScope.Subtree
ds.Filter = "(&(objectClass=user)(SAMAccountName=username))"
Dim sr As SearchResult = ds.FindOne()
sr.GetDirectoryEntry()
Dim de1 As DirectoryEntry = sr.GetDirectoryEntry
Dim memberOf() As String
If Not IsNothing(de1.Properties("memberOf").Value) Then
If TypeOf de1.Properties("memberOf").Value Is String() Then
memberOf = de1.Properties("memberOf").Value
Else
memberOf = New String() {de1.Properties("memberOf").Value}
End If
Else
' No(groups)
End If
' memberOf now contains an array of each DN that the user is a member of
textbox1.Text = de1.Properties("memberOf").Item(0)
End Sub
Also, my end goal is to list all groups a user member is a member of & dump then in a textbox. Please show me what I'm doing wrong! Thanks!
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim de As New DirectoryEntry("LDAP://ab.cd.com", "ab/username", "password", AuthenticationTypes.Secure)
Dim ds As New DirectorySearcher(de)
ds.SearchScope = SearchScope.Subtree
ds.Filter = "(&(objectClass=user)(SAMAccountName=username))"
Dim sr As SearchResult = ds.FindOne()
sr.GetDirectoryEntry()
Dim de1 As DirectoryEntry = sr.GetDirectoryEntry
Dim memberOf() As String
If Not IsNothing(de1.Properties("memberOf").Value) Then
If TypeOf de1.Properties("memberOf").Value Is String() Then
memberOf = de1.Properties("memberOf").Value
Else
memberOf = New String() {de1.Properties("memberOf").Value}
End If
Else
' No(groups)
End If
' memberOf now contains an array of each DN that the user is a member of
textbox1.Text = de1.Properties("memberOf").Item(0)
End Sub