Solved

vba search ldap

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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Simple Linear Regression

728 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