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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:26:57+00:00 2026-05-20T01:26:57+00:00

I am trying to make LDAP queries via Visual Basic. I don’t have administrator

  • 0

I am trying to make LDAP queries via Visual Basic. I don’t have administrator access to the Active Directory, but I am able to view all user objects. I don’t know what restrictions if any there are on me searching the directory via LDAP:// queries.

In the Excel application I am building, I have a column for the input of user IDs. Once a user inputs a user ID, I would like the other columns to be auto-populated based on server side information associated with that user (email address for example)

Let’s say c.Value is the User ID value that has been input to the spreadsheet:

strUser = "CN=" & c.Value & ",OU=User Accounts,OU=Area,OU=Users,OU=Accounts,DC=joe,DC=bloggs,DC=co,DC=uk/"
Set objUser = GetObject("LDAP://" & strUser)

The problem is this — where OU=Area is known, the search is successful. However, I would like the query to check all area OUs for the UserID. As far as I can tell they are not held or mirrored in a central location. Is it possible to use Wildcards in such a query?

Does anyone have any other ideas or suggestions as to alternate ways to go about this?

Thank you,

Tom

  • 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-20T01:26:58+00:00Added an answer on May 20, 2026 at 1:26 am

    Before I answer your question, here are some basic background knowlege on Active Directory.

    • User objects on Active Directory contains a number of attributes.
    • CN is one of the attribute on the user object. It’s not always the same as your login user name.
    • samAccountName is string the pre-Windows 2000 Login Name. This is probably what you are looking for.
    • objects are stored hierarchically. User object can be put under OU or container

    To execute a LDAP query, you need to use an ADO connection object. You need to pass in a LDAP query string to the ADO connection object. The LDAP query string contains four parts.

    • Root path, where we start the search.
    • LDAP filter
    • Returned attributes
    • Search scope

    The LDAP query string that you should use should be something like

    <LDAP://OU=Users,OU=Accounts,DC=joe,DC=bloggs,DC=co,DC=uk>;(&(objectClass=user)(samAccountName=yourusername));adspath;subtree
    
    • The root path in the above example is <LDAP://OU=Users,OU=Accounts,DC=joe,DC=bloggs,DC=co,DC=uk>. It means start searching at this level
    • Since you are searching for user, the LDAP filter is (&(objectClass=user)(samAccountName=yourusername)). Of course, you need to replace yourusername to something else inside your code. If you really want to do the search on CN, change it to CN here
    • Returned attributes is a special attribute adspath, which allows you to bind to that object later
    • I am assuming you are trying to search for all user objects under the same domain. So, your search scope should be subtree

    Here is a complete sample that I guess it should do your job

    userName = "harvey"
    ldapStr = "<LDAP://OU=Users,OU=Accounts,DC=joe,DC=bloggs,DC=co,DC=uk>;(&(objectClass=user)(samAccountName=" & userName & "));adspath;subtree
    
    Set conn = CreateObject("ADODB.Connection")
    conn.Provider = "ADSDSOObject"
    conn.Open "ADs Provider"
    Set rs = conn.Execute(ldapStr)
    
    While Not rs.EOF
       wscript.echo rs.Fields(0)
       rs.MoveNext
    Wend
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.