[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB6 reading Firstname, Lastname and email from Active Directory

Posted on 2004-11-10
7
Medium Priority
?
1,333 Views
Last Modified: 2008-01-09
Hi

I want to read Firstname, Lastname and email Address from ADS.

I tried this:

    Dim RS As ADODB.Recordset
    Dim cnn As ADODB.Connection
    Dim cmd As ADODB.Command
    Set cnn = CreateObject("ADODB.Connection")
    Set cmd = CreateObject("ADODB.Command")

    cnn.Provider = "ADsDSOObject"  ' This is the ADSI OLE-DB provider name
    cnn.Open ("Active Directory Provider")

    cmd.ActiveConnection = cnn
    cmd.CommandText = "select name, distinguishedname, memberOf from 'LDAP://" & DOMAINCONTROLLER & "/OU=TKN-Kr,OU=User,OU=Administration,DC=kt,DC=tkw,DC=com' WHERE objectCategory='user' ORDER By Name"
    cmd.Properties("Page Size") = 1000
    cmd.Properties("Timeout") = 30
    cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE 'search all containers
    cmd.Properties("Cache Results") = False


I can get RS.Fields("name") containing the shown name. But sometimes it includes a comma, sometimes not. So I want to read firstname and lastname seperately.

But I cannot add lastname or any other field to my SQL string, always an error comes up then. Why not???

Thank you.
0
Comment
Question by:MPKR
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Expert Comment

by:Dudge669
ID: 12545163
Instead of using the "name" property, use .sn  for surname (last name) and .givenname for first name.
0
 
LVL 3

Expert Comment

by:paix120
ID: 12548435
What is the error you get when you add lastname to the SQL string? Is lastname a field in the table you are reading from? If not, you will have to perform a string function on the name field. Please give more info.
Paix120
0
 
LVL 2

Expert Comment

by:Dudge669
ID: 12548466
He was probably using the property name "lastname".  MPKR, is this what you wanted to add?:

"select name, distinguishedname, memberOf, sn, givenname from...."
0
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.

 
LVL 3

Accepted Solution

by:
paix120 earned 150 total points
ID: 12548515
Also give examples of the data in the name field

If it is displayed as "Smith, John", create this variable to return "John":

dispname=RIGHT(RS.Fields("name") , (LEN(RS.Fields("name") )-INSTR(",", RS.Fields("name") , 1)))

It finds the location of the comma in the string, then returns everything to the right of the comma. However, string functions will be complicated if not all of the names are formatted in the same way.

If this is what you want to do, more info would help me solve your problem
0
 
LVL 4

Author Comment

by:MPKR
ID: 12553434
@paix20: I don't have no table to look up what kind of fields are in cause I want to read the ADS.
@Dudge: Yes, thats it, I tried those Attributes, I found them in ms.com, but they don't work!

If I incluce filds like LASTNAME or FIRSTNAME or SURNAME (..), the application does not work at all and brings this err.desc-err.number:

"unknown error - 2147467259"

The used SQL is for example:
select name, lastname, distinguishedname, memberOf from 'LDAP://ktkrs2000/OU=TKN-Di,OU=Benutzer,OU=Administration,DC=ktn,DC=tk,DC=com' WHERE objectCategory='user' ORDER By name
Set RS = cmd.Execute
'(...)

Whenever I try to concat my names from the displayed name (field "name") I also get errors, cause sometimes the ADS (including more then 2000 entries) is not administrated correctly, so first/last are turned rund, comma is missing, fields are empty ... I can not go tis way.

So I tried the following:

select name, distinguishedname, memberOf from 'LDAP://ktkrs2000/OU=TKN-Di,OU=Benutzer,OU=Administration,DC=ktn,DC=tk,DC=com' WHERE objectCategory='user' ORDER By name
'(...)
Dim objUser As Object
Set objUser = GetObject("LDAP:// " & strDistName & "")
u_Lastname = objUser.Lastname
u_Firstname = objUser.Firstname
'(...)

THIS WORKS NOW!!
But this looks very funny and complicated and tricky to me. Is this the right way to go??

0
 
LVL 2

Assisted Solution

by:Dudge669
Dudge669 earned 150 total points
ID: 12555218
If it works, why not? It could be that someone else in your company changed around your AD schema.  Whatever works! :)
0
 
LVL 4

Author Comment

by:MPKR
ID: 12555589
Sometimes I wonder if anyone ever understood the dos and do nots of contacting ADS with different languages/technologies.

I never found any example in the web that works. None can tell me how you should start off, nobody can give adivce where the mistakes are... :)


Does anyone know a good book I could buy to get to get an introduction into programming ADS with ASP/ASP .NET / VB ??
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

872 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