Comate and LDAP (active directory)

Just starting out? Need help? Post your questions and find answers here.
User avatar
jackymb
User
User
Posts: 16
Joined: Wed Aug 11, 2004 7:37 pm
Location: AIX en PROVENCE (France)

Comate and LDAP (active directory)

Post by jackymb »

Hi,

how to read user info in active directory ?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

http://support.microsoft.com/default.as ... us;Q328024

Should get you started and looks easy enough to convert to PB with COMate.
I may look like a mule, but I'm not a complete ass.
User avatar
jackymb
User
User
Posts: 16
Joined: Wed Aug 11, 2004 7:37 pm
Location: AIX en PROVENCE (France)

Post by jackymb »

Thank you srod.

But I use ADO in vbscript to read Active directory. I translated that into PB and I get an error

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
Post Reply