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
Before I answer your question, here are some basic background knowlege on Active Directory.
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.
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>. It means start searching at this level(&(objectClass=user)(samAccountName=yourusername)). Of course, you need to replaceyourusernameto something else inside your code. If you really want to do the search on CN, change it to CN hereadspath, which allows you to bind to that object latersubtreeHere is a complete sample that I guess it should do your job