We help IT Professionals succeed at work.

VB Script - LDAP question

Medium Priority
Last Modified: 2010-04-17
My code errors out saying "One or more errors occurred during processing of command."  Source provider
set adorecordset = adoconnection.execute ("ldap://MyLdapServer.MyInternalDomain.MyExternalDomain.com:389/OU=MyUsers,DC=MyInternalDomain,DC=MyExternalDomain,DC=com")

''''''''''''''''''''''''''''''''''''Entire code
Dim adoConnection
Dim adoRecordset
Dim str

set adoConnection = CreateObject ("ADODB.Connection")
adoConnection.Provider = "ADSDSOObject"
adoConnection.Open "", "CN=MyInternalDomain/administrator,CN=Users,DC=MyInternalDomain,dc=MyExternalDomain,dc=com", "dinglberry"
set adorecordset = adoconnection.execute ("ldap://MyLdapServer.MyInternalDomain.MyExternalDomain.com:389/OU=RELTDUsers,DC=MyInternalDomain,DC=MyExternalDomain,DC=com")
Set adoRecordset = Nothing

Watch Question

Artysystem administrator
Top Expert 2007

I'm not a master in VB, but have some experience with LDAP search filters. If you are shure that connection is established,  try another syntax:
set adorecordset = adoconnection.execute ("(objectclass=*)")
gabesoSolution Architect

Shouldn't it be:


You are missing a whole bunch of stuff. Just replace the servername, ou structure and don't search for the administrator userid. I just put that because you referenced it above. If you have the rights to do that then fine.


Dim adoConnection
Dim adoRecordset
Dim str

set adoConnection = CreateObject ("ADODB.Connection")
adoConnection.Provider = "ADSDSOObject"
adoConnection.Open "Active Directory Provider"

Dim Base
Dim Filter
Dim Attributes
Dim Level

Base = "<LDAP://MyLdapServer/OU=RELTDUsers,DC=MyInternalDomain,DC=MyExternalDomain,DC=com>;"
' You may not have the rights to display the administrator account. Choose another userid

Filter = "(&(objectClass=user)(objectCategory=person)(samAccountName=Administrator));"
Attributes = "displayName;"
Level = "SubTree"

set adorecordset = adoconnection.execute (Base & Filter & Attributes & Level)

While Not adorecordset.EOF
    Wscript.echo adorecordset.Fields(0).Value & vbCrLf
Set adoRecordset = Nothing

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


tone28 could you recommend a book on this subject?  The code above was great and worked pretty much right out of the gate.

What we are trying to do is authenticate a username and password.

If you are in a domain then the code will use your credentials. There are options to add a username and password if you need to do some automated process id type work. Also there are options to encrypt passwords sent.

For books I would recommend Robbie Allen.




He is a great author and even has example on his website. I would warn though use his examples to learn how to do it rather than any cut and paste jobs. Let me know if you have any more specific questions. I would be happy to help.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.