Solved

vba search ldap

Posted on 2006-06-12
5
925 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

860 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