Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get FirstName & LastName from Active Directory 1

Status
Not open for further replies.

aspvbnetnerd

Programmer
May 16, 2006
278
SE
I have this code to validate a login to a Active Directory.
Code:
Private Function ValidateActiveDirectoryLogin(ByVal Domain As String, ByVal Username As String, ByVal Password As String) As Boolean Implements IActiveDirectory.ValidateActiveDirectoryLogin

    Dim Success As Boolean = False
    Dim Entry As New System.DirectoryServices.DirectoryEntry("LDAP://" & Domain, Username, Password)
    Dim Searcher As New System.DirectoryServices.DirectorySearcher(Entry)
    Searcher.SearchScope = DirectoryServices.SearchScope.OneLevel
    Try
        Dim Results As System.DirectoryServices.SearchResult = Searcher.FindOne

        If (My.User.IsInRole(AD_GROUP)) Then
            Success = Not (Results Is Nothing)
        End If
    Catch
        Return False
    End Try

    Return Success

End Function
Now I also want to retrieve the user FirstName and LastName from Active Directory.
Does anyone have experience working with DirectoryServices and can help me with my problem?

/George
 
I don't know the exact names of the fields you are looking for but this should get you started.

Code:
Dim givenname as String = Results.InvokeGet("givenName").ToString

which you can add after these lines.

Code:
If (My.User.IsInRole(AD_GROUP)) Then
            Success = Not (Results Is Nothing)
        End If


Christiaan Baes
Belgium

My Blog
 
I tried this today and in Result it does not exists any function called "InvokeGet"
chrissie1, do you have any other ideas?

/George
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top