Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search for user with LDAP query

Status
Not open for further replies.

SPV550

Programmer
Aug 1, 2006
6
GB
Hello

I created a code via VB6 which allows me to search for a user in active directroy and then displays the users details that i require:

Assuming this is the hierarchical structure of Active Directory:

Root - First level - Second Level - Third Level

Dim user as IADsuser

"LDAP://CN=" + User + ",OU=Second Level,OU=First Level,DC=domain,DC=co,DC=uk"

lbluser.Caption = user.Get("Department")

' Displays the department the user is in.

(NOTE: Above LDAP is broken into two parts first ("LDAP://CN=") + User + is using the text entered in a textbox to serach for and the the second half of the LDAP code comes along)

This works fine when searching for any user under the second level (second level as displayed in active directory)
but users that are found in any other directory are not displayed. I have added subtree at the end of the LDAP query and still makes no difference. I would like to know how to search all of active directory so any user regardless of what level theyre in woudl display their information.

If you have any questions please ask and thank you in advance for any help given.
 
[1] Subtree is the subtree of the tree structure starting from the base which is what you suggested "cn=...,ou=second level,...". Since that base is a leaf object, subtree lost its significance.

[1.1] Hence, if you want to do a full search start from the domain root, you have to make the base something like this (without the rdn part of cn=... at least).
[tt] "<LDAP://DC=domain,DC=co,DC=uk>"[/tt]

[1.2] In the filter, you specify what kind of object you want to serach.
[tt] "(&(objectClass=User)(cn=" & susername & "))"[/tt]

[1.3] Then you can specify you want a subtree search.

[2] In your excerpt, you dim user as iadsuser. But then, you use "user" as if it is a string in your search base. Maybe you simplify too much for the post. It is definitely a mixed up of variable types.
 
Thanks for your reply. Sorry i must have made a typo in my code i forgot to add a String variable. So it shoudl have looked like:

Dim user as IADsuser
Dim userName as String

userName = txtUser.Text

Set user = GetObject ("LDAP://CN=" + userName + ",OU=Second Level,OU=First Level,DC=domain,DC=co,DC=uk")

lbluser.Caption = user.Get("Department")

' Displays the department the user is in.

Im slightly lost here.... my code for LDAP and to serach for the user reads:

Set user = GetObject("LDAP://CN=" + userName + ",DC=domain,DC=co,DC=uk","(&(objectClass=User)(cn=" & userName & "))")

i guess i have something wrong??

Thanks again for any help
 
OK thanks..... Just so i know are you referring this documentation as i have gone the wrong way about retrieving data from AD with my code or is this to help me build the syntax for the LDAP query?
 
>Just so i know are you referring this documentation as i have gone the wrong way about retrieving data from AD with my code or is this to help me build the syntax for the LDAP query?
But you line is so off... I would therefore say both. There is no guessing in this area of coding only the documentation is your friend.
 
Thanks for your help so far..... ive read the documenataion etc and copied the code from the link you sent, inserted our details. When it gets to the code line:

' Execute the query.
Set rs = Com.Execute

i get an error message saying

runtime error 2147217911 (80040e09) Permission denied.

Im using an LDAP query modified to our details (from the link you sent) and using administrator logins.

Any advice?

thanks
 
I wonder aloud how people debug anything at all?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top