Public Function GetUserInfo(ByVal inSAM As String, ByVal inType As String) As String Try**** ' Dim sPath As String = "LDAP://****.com/DC=****,DC=com" Dim sPath As String = "LDAP://****.com" Dim SamAccount As String '= Right(inSAM, Len(inSAM) - InStr(inSAM, "\")) SamAccount = 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 '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 Return "Null" Exit Function 'do some error return here. End Try End Function
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)