VB6 reading Firstname, Lastname and email from Active Directory
Posted on 2004-11-10
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???