Solved

vba search ldap

Posted on 2006-06-12
5
916 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
  • 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 500 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now