Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vba search ldap

Posted on 2006-06-12
5
Medium Priority
?
931 Views
Last Modified: 2008-01-09
I'm in access and I want to in vba search a ldap (active directory) for a certain user and grab there display name and email address. I have achived this in c# but for vba I know it is 100% different.

Can someone please show me in coding how to do this..

thanks
0
Comment
Question by:bman9111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:bpmurray
ID: 16888774
Try something like this:


    ' This is specific to your installation, but it's something like this
    Dim ADsPath As String
    ADsPath = "LDAP://directorydev.experts.com/aid=???,ou=Applications,o=experts.com,c=ie"
   
    ' Define the ADO connection
    Dim connection As ADODB.connection
    Set connection = New ADODB.connection
    connection.Provider = "ADSDSOObject"
    connection.Properties("User ID") = "cn=Directory Manager"
    connection.Properties("Password") = "foobar"
    connection.Open "ADSI"

   
    ' We need a command
    Dim command As ADODB.command
    Set command = New ADODB.command
    command.ActiveConnection = connection
    ' I'm not sure about this syntax
    command.CommandText = "<" & ADsPath & ">;(userreferencedn=*xternal*);ADsPath;subtree"
     
    ' This is returned as a data set
    Dim recordset As ADODB.recordset
    Set recordset = command.Execute
    recordset.MoveFirst
    While Not recordset.EOF
        ' Process the returned value
        recordset.MoveNext
    Wend
       
    ' OK we're finished - drop the connection
    connection.Close
0
 
LVL 8

Author Comment

by:bman9111
ID: 16888836
what parts am I suppose to replace with my data???

0
 
LVL 8

Author Comment

by:bman9111
ID: 16888857
meaning my domain name is

Hutwork

Username is Jted
Password is Ted

and I need to see what the user display name which would be

Jimmy Ted

Any ideas
0
 
LVL 8

Author Comment

by:bman9111
ID: 16890469
any ideas???
0
 
LVL 15

Accepted Solution

by:
bpmurray earned 2000 total points
ID: 16892617
Unfortunately, I don't have access to an ADS right now, so I can't be sure this will work. However, type it in, and see how well it works. The idea is to pass in the "JTed" as a parameter, i.e. ShortName, and the data should then be returned. As I said, I haven't been able to test it, but it's pretty darn close :-)



Sub getUserInfo(shortName)

    ' Define the ADO connection
    Dim connection As ADODB.connection
    Set connection = CreateObject("ADODB.Connection")
    connection.Provider = "ADSDSOObject"
    ' You may have to provide your AD manager credentials here
    connection.Properties("User ID") = "cn=Directory Manager"  'YOURS
    connection.Properties("Password") = "foobar" 'YOURS
    connection.Open "ADs Provider"

   
    ' We need a command
    Dim command As ADODB.command
    Set command = New ADODB.command
    command.ActiveConnection = connection
   
    ' Set up the command ...
    Set rootDSE = GetObject("LDAP://RootDSE")
    DomainContainer = rootDSE.Get("defaultNamingContext")
    CommandStr = "<LDAP://" & DomainContainer & ">;(&(objectCategory=user)(mailNickname=" & shortName & "));ADsPath;subtree"
     
    ' This is returned as a data set
    Dim recordset As ADODB.recordset
    Set recordset = command.Execute(CommandStr)
    recordset.MoveFirst
    While Not recordset.EOF
        ' Process the returned value
        FullName = GetProperty(sResultSet, "cn")
        FirstName = GetProperty(sResultSet, "givenName")
        MiddleInitials = GetProperty(sResultSet, "initials")
        LastName = GetProperty(sResultSet, "sn")
        Address = GetProperty(sResultSet, "homePostalAddress")
        recordset.MoveNext
    Wend
       
    ' OK we're finished - drop the connection
    connection.Close

End Sub
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Introduction to Processes
Starting up a Project

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question