Active Directory get user List
I am trying with this code to change the password of a user in active directory.
Code:
rivate Sub button1_Click(sender As Object, e As EventArgs)
Try
' Use the user account you're changing the password on
' to validate the user really exists. Specifies the
' authentication type as secure as I had problems
' getting it to work otherwise.
Dim entry As New DirectoryEntry("LDAP://CN=Users,DC=domaim,DC=com", "Domain\Administrator", "password", AuthenticationTypes.Secure Or AuthenticationTypes.Sealing Or AuthenticationTypes.ServerBind)
Dim search As New DirectorySearcher(entry)
search.Filter = "(SAMAccountName=testuser)"
Dim result As SearchResult = search.FindOne()
Dim user As DirectoryEntry = result.GetDirectoryEntry()
Dim ret As [Object] = user.Invoke("ChangePassword", New Object() {"password", "newpassword"})
user.CommitChanges()
Catch exception As Exception
Console.WriteLine(exception.Message)
End Try
End Sub
But this is returning the result as Logon failure. But I am sure the user name and password are correct
Any ideas ?