Comate and LDAP (active directory)
Posted: Fri Dec 19, 2008 7:38 pm
Hi,
how to read user info in active directory ?
how to read user info in active directory ?
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
IncludePath #PB_Compiler_Home + "Include\"
XIncludeFile "COMate.pbi"
#False = 0
#True = 1
#ADS_SCOPE_SUBTREE = 2
Define.COMateObject oCnx, oCmd, oRSetAD
Define.s strDom, strMyOu, strOu, strFilter, strAttributes, strQuery, strBase
Define.s strSGI, strNom, strPrenom, strCN
Define.l icpt, iCptMail
strDom = "DC=Dom,DC=net"
strMyOu = "OU=MyOU,"
strOu = "OU=Users,"
strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=*))"
strAttributes = "cn,sAMAccountName,sn,givenname, mail"
strQuery = "<LDAP://" + strOu + strMyOu + strDom + ">;" + strFilter + ";" + strAttributes + ";subtree"
;Set objConnection = CreateObject("ADODB.Connection")
oCnx = COMate_CreateObject("ADODB.Connection")
If oCnx
;objConnection.Open "Provider=ADsDSOObject;"
oCnx\SetProperty("Provider='ADsDSOObject;'")
;Set objCommand = CreateObject("ADODB.Command")
oCmd = COMate_CreateObject("ADODB.Command")
If oCmd
oCmd\SetProperty("ActiveConnection(oCnx)")
;objCommand.Properties ("Page Size") = 1000
oCmd\SetProperty("Properties('Page Size') = 1000")
;objCommand.Properties ("Size Limit") = 5000
oCmd\SetProperty("Properties('Size Limit') = 5000")
;objCommand.Properties ("Timeout") = 30
oCmd\SetProperty("Properties('Timeout') = 30")
;objCommand.Properties ("Cache Results") = False
oCmd\SetProperty("Properties('Cache Results') = #FALSE")
; objCommand.Properties ("searchscope") = ADS_SCOPE_SUBTREE
oCmd\SetProperty("Properties('searchscope') = #ADS_SCOPE_SUBTREE")
;objCommand.CommandText = strQuery
;Set objRecordSet = objCommand.Execute
; SQL$ = "Select * from TestTable"
; adoRecordSet = adoConnection\GetObjectProperty("Execute('" + SQL$ + "')")
; Debug "SELECT sAMAccountName FROM LDAP://" + strOu + strOUPaca + strdom + " WHERE objectClass=user =users"
; strQuery = "SELECT sAMAccountName FROM LDAP://" + strOu + strOUPaca + strdom + " WHERE objectClass=user =users"
Debug "<LDAP://" + strOu + strOuPaca + strDom + ">;" + strFilter + ";" + strAttributes + ";subtree"
oCmd\SetProperty("CommandText('<LDAP://" + strOu + strOuPaca + strDom + ">;" + strFilter + ";" + strAttributes + ";subtree')")
;Set objRecordSet = objCommand.Execute
oRSetAD = ocmd\Invoke("Execute")
; oRSetAD = ocmd\GetObjectProperty("Execute('" + strQuery + "')")
; oRSetAD = ocmd\Invoke("Execute('"Select sAMAccountName FROM LDAP://" + strOu + strOUPaca + strdom + " WHERE objectClass=user =users"')")
If oRSetAD
; oRSetAD\Invoke("MoveFirst")
;Repeat
; EOF = oRSetAD\GetIntegerProperty("EOF")
Debug EOF
While oRSetAD\GetIntegerProperty("EOF") <> -1
; If EOF = -1 ;Variant_TRUE
; Break
; EndIf
ID$ = oRSetAD\GetStringProperty("Fields('sAMAccountName')\Value")
; Integer$ = adoRecordSet\GetStringProperty("Fields('IntegerField')\Value")
; Text$ = adoRecordSet\GetStringProperty("Fields('TextField')\Value")
; Memo$ = adoRecordSet\GetStringProperty("Fields('MemoField')\Value")
; Debug "(ID=" + ID$ + ", IntegerField=" + Integer$ + ", TextField=" + Text$ + ", MemoField=" + Memo$ + ")"
Debug ID$
oRSetAD\Invoke("MoveNext")
; ForEver
Wend
oRSetAD\Invoke("Close")
oRSetAD\Release()
Else
MessageRequester("2-COMate - ADO demo", "Couldn't create the recordset object!")
EndIf
Else
MessageRequester("1-COMate - ADO demo", "Couldn't create command object!")
EndIf
EndIf