Use DirectoryServices DirectoryEntry without passing userid or password.

Posted on 2009-04-28
Last Modified: 2012-05-06
I am trying to use the DirectoryServices' DirectoryEntry class to retrieve the email address for a given user. I do not want to pass a user id/password, but would rather use windows authentication. The only way I could get it to work though is to pass a valid user and password. Is there a way to do this without a userid/password?

Dim adPath As String = String.Format("LDAP://<SID={0}>", userSid)

        'Create DE object

        Dim sidBind As DirectoryEntry = New DirectoryEntry( _

            adPath, _

            "", _


        'retrieve e-mail address property

        If sidBind.Properties.Contains("mail") Then

            Return sidBind.Properties("mail").Value.ToString()


            Return String.Empty

        End If

Open in new window

Question by:MikeBroderick
    LVL 9

    Accepted Solution

    <authentication mode="Windows" />
    <identity impersonate="true"/>
    and by passing : User.Identity.Name
    further check :

    Author Comment

    That did it. One of my attempts would have worked except I passed "" (null string) as the password instead of the keyword nothing:
                Dim sidBind As DirectoryEntry = New DirectoryEntry( _
                    adPath, _
                    LogInName, _
                    Nothing, _

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Mapping Drives using Group policy preferences Are you still using old scripts to map your network drives if so this article will show you how to get away for old scripts and move toward Group Policy Preference for mapping them. First things f…
    Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
    This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
    This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

    755 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

    22 Experts available now in Live!

    Get 1:1 Help Now