By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,246 Members | 1,480 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,246 IT Pros & Developers. It's quick & easy.

search special group in active directory by

P: n/a
hello this is my code could anyone help me, I want to search exact user in special group in active directory, my group name is test11 . could anyone here help me to do this.
thanks this is my code

Public Function ValidateUser(ByVal Domain As String, ByVal username As String, ByVal password As String) As Boolean

Dim strGroupDN As String
strGroupDN = "Users"

Dim de As New DirectoryEntry("LDAP://" & Domain, username, password, AuthenticationTypes.Secure)
Dim srch As New DirectorySearcher(de)

' srch.Filter = "(objectClass=Group)"
'srch.SearchScope = SearchScope.Subtree
'srch.Filter = "(&(ou=hh)(cn=test11))"
srch.Filter = "(&(objectClass=user)(samAccountName=" & username & "))"

de.Invoke("Groups", New Object() {"test11"})
'srch.Filter = "(&(objectCategory=Person)(objectClass=user)(ou=hh )"

' srch.Filter = "(&(objectClass=user)(samAccountName=" & username & ")(memberOf=" & strGroupDN & "))"
Dim result As SearchResult = srch.FindOne

If Not result Is Nothing Then

Return True
Return False
End If
Catch ex As Exception
Console.Write(ex.Message + ControlChars.NewLine + ex.StackTrace)
Return False
End Try
End Function
From: Sara

Posted by a user from .NET 247 (

Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.