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 9204149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:38:24+00:00 2026-06-17T23:38:24+00:00

I am trying to query Active directory for a user to get a list

  • 0

I am trying to query Active directory for a user to get a list of details:
1. First/Last Name
2. Email
3. UserName
4. Domain

I am able to get all except for the domain name. Here is my code:

    Dim oroot As DirectoryEntry = New DirectoryEntry("GC://ldap.someCompany.com")
    Dim osearcher As DirectorySearcher = New DirectorySearcher(oroot)
    Dim result As SearchResult

    osearcher.Filter = String.Format("(&(SAMAccountName={0}))", "myUsername")
    osearcher.PropertiesToLoad.Add("cn")
    osearcher.PropertiesToLoad.Add("SAMAccountName")   'Users login name  
    osearcher.PropertiesToLoad.Add("givenName")    'Users first name  
    osearcher.PropertiesToLoad.Add("sn")   'Users sur name  
    osearcher.PropertiesToLoad.Add("mail")   'Email address

    result = osearcher.FindOne

    Try
        myUser.UserID = result.Properties("cn").Item(0)
        myUser.Domain = ""
        myUser.EmailAddress = result.Properties("mail").Item(0)
        myUser.FirstName = result.Properties("givenName").Item(0)
        myUser.LastName = result.Properties("sn").Item(0)
        myUser.Domain = result.Properties("displayName").Item(0)

    Catch ex As Exception
        Return Nothing
    End Try

This returns this string: GC://ldap.someCompany.com/CN=FirstName M LastName,OU=Employees,OU=Domain Users,DC=val1,DC=val2,DC=com

So, I have two questions. First, how do I get the domain name of the user? It appears to be in DC= (where I have val1)
Second, is there anyway to speed this search up? Right now, it takes about 10 seconds to run the query.

I am using .net 4.0 and Visual Studio 2010
Thanks for any help

jason

  • 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-06-17T23:38:25+00:00Added an answer on June 17, 2026 at 11:38 pm

    Strart from right and read the DC components, then you have the realm/domain of the account. See RFC2247.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to query the Active directory to get a list of users in
Trying to query a 'Favorites' model to get a list of items a user
I am trying to query a list of users within a specific active directory
I am using ASP.Net 4.0 MVC to query active directory. I am trying to
I'm trying to list everyone in a security group in an active directory without
How can i get the IADs interface of an Active Directory user - by
I am running a test Active directory and am trying to query with ldap.
I'm trying to query a list and get newsletter articles back that match the
I'm trying to find the simplest way to query Active Directory, in one of
I am trying to query nearly all users in Active Directory. My normal users

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.