Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB active directory
Hi,
 
I am looking for a sample program that can grab a users information. I have acquired the Active Directory string. See below:
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
 
I'm just not sure what to do with the code above to make it grab users data by looking up a username.
Posted 12-Mar-13 9:35am
anoble1253
Comments
Yvan Rodrigues at 12-Mar-13 19:29pm
   
I don't have time to answer right now, but you may find this article I wrote helpful (ignore the Apache stuff):
http://ist.uwaterloo.ca/security/howto/2005-12-20/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 12 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100