Kbase P25103: How to read information from the Active Directory using ADO
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  25/10/2005 |
|
Status: Verified
GOAL:
How to read information from the Active Directory using ADO
FIX:
The following program gives you an example on how to read user account information from the Active Directory using ADSI through ADO. For more information please refer to the Microsoft MSDN website at http://www.msdn.com .
DEFINE VARIABLE dDateInit AS DATE INITIAL "1/1/1601" NO-UNDO.
DEFINE VARIABLE dLastLogon AS DECIMAL NO-UNDO.
DEFINE VARIABLE dpwdLastSet AS DECIMAL NO-UNDO.
DEFINE VARIABLE chConn AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chRS AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE iRecordsAffected AS INTEGER NO-UNDO.
DEFINE VARIABLE iOptions AS INTEGER NO-UNDO.
DEFINE VARIABLE cQuery AS char NO-UNDO.
/* Create the connection to the ADSI OLE DB provider */
CREATE "ADODB.Connection" chConn NO-ERROR.
chConn:Provider = "ADsDSOObject".
chConn:OPEN = "ADSI Providers".
/* Create recordset object to return data */
CREATE "ADODB.Recordset" chRS NO-ERROR.
/* Create and execute SQL statement */
/* Change servername and username */
cQuery = "SELECT name,lastLogon,pwdLastSet FROM
'LDAP://home.net/cn=users,dc=home,dc=net' WHERE objectClass='user' AND cn='Administrator'".
chRS = chConn:EXECUTE(cQuery,OUTPUT iRecordsAffected,iOptions).
DO WHILE NOT chRS:EOF:
/* Calculate UTC value, Time Zone Bias in this example is 60 minutes (+1) */
dLastLogon = TRUNCATE((((chRS:FIELDS("lastLogon"):VALUE:HighPart * EXP(2,32)) +
chRS:FIELDS("lastLogon"):VALUE:Lowpart) / 600000000 + 60) / 1440, 0).
dpwdLastSet = TRUNCATE((((chRS:FIELDS("pwdLastSet"):VALUE:HighPart * EXP(2,32)) +
chRS:FIELDS("lastLogon"):VALUE:Lowpart) / 600000000 + 60) / 1440, 0).
MESSAGE
"Username: " chRS:FIELDS("name"):VALUE SKIP
"Last Logon: " dDateinit + dLastLogon SKIP
"Last Password Change: " dDateinit + dpwdLastSet
/* Multivalued fields (description, memberOf, etc.) cannot be accessed */
VIEW-AS ALERT-BOX INFO BUTTONS OK.
chRS:MoveNext.
END.
RELEASE OBJECT chRS.
RELEASE OBJECT chConn.