Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1062965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:42:42+00:00 2026-05-16T18:42:42+00:00

I’m using the following code, which works, to login a user to an application

  • 0

I’m using the following code, which works, to login a user to an application built in VB.NET against active directory.

This code works great but I need to retreive the user’s first name, last name, display name and also check if the user is part of a group.

I’ve tried many forms of adResults.Property(“displayname”).ToString() and the like but just can’t get it to work right.

Anyone have any ideas how to do what I’m looking to do?

Here’s the code I’m using now and thanks in advance.

Public Function ValidateActiveDirectoryLogin(ByVal sDomain As String, ByVal sUserName As String, ByVal sPassword As String) As Boolean

    Dim bSuccess As Boolean = False
    Dim adEntry As New System.DirectoryServices.DirectoryEntry("LDAP://" & sDomain, sUserName, sPassword)
    Dim adSearcher As New System.DirectoryServices.DirectorySearcher(adEntry)
    adSearcher.SearchScope = DirectoryServices.SearchScope.OneLevel
    Try
        Dim adResults As System.DirectoryServices.SearchResult = adSearcher.FindOne
        bSuccess = Not (adResults Is Nothing)
    Catch ex As Exception
        bSuccess = False
        MsgBox("Error")
    End Try

    Return bSuccess

End Function 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:42:42+00:00Added an answer on May 16, 2026 at 6:42 pm

    Look at the System.DirectoryServices.AccountManagemment namespace. The userprincipal object has everything you need and more. Here’s an explanation on how to use this API.

    EDIT: it’s really much simpler to use actually. Have a look at this sample code:

    Dim userName = Environment.UserName
    
    ' create a domain context
    Dim DC = New PrincipalContext(ContextType.Domain)
    
    ' find a user in the domain
    Dim user = UserPrincipal.FindByIdentity(DC, userName)
    
    ' get the user's groups
    Dim groups = user.GetGroups()
    
    ' get the user's first and last name
    Dim firstName = user.GivenName
    Dim lastName = user.SurName
    
    ' get the distinguishednames for all groups of the user
    Dim groupNames = From g in groups Select g.DistinguishedName
    ' etc...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.