Full name of user out of Active Directory

Posted on 2006-04-30
Last Modified: 2010-04-23
I am trying to get the full name of a user (Jeff Reed) by using the login name of (jreed).  The server name is Crash1 @ and the domain is as seen below.  I have tried this ten different ways and can not get “Jeff Reed” out of it.  Yes, Jeff Reed actually exists in Active Directory and his login is jreed.  Where have I gone wrong and how do I get this up and running?

My.User.Name.ToString returns “jreed”

Private Function GetFullName(ByVal pName As String) As String
        Dim domainEntry As DirectoryEntry
        Dim searcher As DirectorySearcher
        Dim results As DirectoryServices.SearchResultCollection
        Dim fullName As String = Nothing
        Dim principleName As String = Nothing

        domainEntry = New DirectoryEntry("LDAP://")
        searcher = New DirectorySearcher(domainEntry, "userprinciplename = " + pName)
        results = searcher.FindAll()
        If (results.Count > 0) Then
            fullName = results(0).GetDirectoryEntry.Properties("givenName").Value.ToString & vbNewLine & _
        End If
        Return Name
End Function
Question by:jsyers
    LVL 1

    Accepted Solution

     Dim User As IADsUser
     Dim dirEntry As System.DirectoryServices.DirectoryEntry

    dirEntry = New System.DirectoryServices.DirectoryEntry("WinNT://,user")

    User = CType(dirEntry.NativeObject(), IADsUser)

    YOU WILL NEED TO ADD A REFERENCE TO THE Active DS Type Library for it to pickup the IADsUser Class

    LVL 1

    Expert Comment

    It would be fairier to say they cant be bothered to mark the question as answered, and hence not cost themselves any points.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now