Link to home
Start Free TrialLog in
Avatar of Mike Broderick
Mike BroderickFlag for United States of America

asked on

Use DirectoryServices DirectoryEntry without passing userid or password.

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()
        Else
            Return String.Empty
        End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Sreedhar Vengala
Sreedhar Vengala
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike Broderick

ASKER

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, _
                AuthenticationTypes.Secure)