Home All Groups Group Topic Archive Search About

search user in active directory

Author
5 Oct 2006 5:31 PM
sgr
How do I search an user into the active directory from a vb.Net application?

Thanks for all.

Author
6 Oct 2006 1:51 AM
Siva M
There are many samples. A Google search may help you in this. Here is one
for your quick reference:
http://msdn2.microsoft.com/en-us/library/ms180881.aspx

"sgr" <s**@discussions.microsoft.com> wrote in message
news:EC9C54C8-7721-42B7-9CE2-99B8D45A4280@microsoft.com...
How do I search an user into the active directory from a vb.Net application?

Thanks for all.
Author
31 Oct 2006 6:54 PM
De Roeck
I found following code, but haven't tested it yet. But it's surely
with System.DirectoryServices.

Public Function GetUserInfo(ByVal inSAM As String, ByVal inType As
String) As String
  Try



     Dim sPath As String =
"LDAP://yourdomainpath.com/DC=yourdomainpath,DC=com"
     Dim SamAccount As String = Right(inSAM, Len(inSAM) - InStr(inSAM,
"\"))
     Dim myDirectory As New DirectoryEntry(sPath, "Enterprise Admin",
"Password") 'pass the user account and password for your Enterprise
admin.
     Dim mySearcher As New DirectorySearcher(myDirectory)
     Dim mySearchResultColl As SearchResultCollection
     Dim mySearchResult As SearchResult
     Dim myResultPropColl As ResultPropertyCollection
     Dim myResultPropValueColl As ResultPropertyValueCollection 
'Build LDAP query
     mySearcher.Filter = ("(&(objectClass=user)(samaccountname=" &
SamAccount & "))")
    mySearchResultColl = mySearcher.FindAll()
'I expect only one user from search result
     Select Case mySearchResultColl.Count
          Case 0
             Return "Null"
             Exit Function
          Case Is > 1
            Return "Null"
            Exit Function
    End Select



   'Get the search result from the collection
    mySearchResult = mySearchResultColl.Item(0) 



    'Get the Properites, they contain the usefull info
    myResultPropColl = mySearchResult.Properties



    'displayname, mail
    'Retrieve from the properties collection the display name and
email of the user
     myResultPropValueColl = myResultPropColl.Item(inType)
    Return CStr(myResultPropValueColl.Item(0))



  Catch ex As System.Exception



    'do some error return here.
  End Try
End Function


Succes

On Thu, 5 Oct 2006 10:31:02 -0700, sgr <s**@discussions.microsoft.com>
wrote:

Show quoteHide quote
>ser into the active directory from a vb.Net