Using VBScript to access data on LDAP  
Author Message
rahulverma





PostPosted: Top

VB Scripts >> Using VBScript to access data on LDAP

To the best of my knowledge I'm trying to retrieve data from an iPlanet LDAP
Server. I want to create a user-friendly interface that will allow us to
update the data stored in the LDAP server. Most of the programming I've been
doing has been against Windows 2003 AD, and I seem to be able to connect to
the server, but nothing is getting returned, rather nothing USEFUL is coming
back.

I ran a query against the LDAP server to return the CN of all objects that
are owned by me, which is 3. I receive 3 hits but it returns null, I believe
the code is fairly straightforward I based it off the code listed here:

http://www.hide-link.com/

Here is my version of that code:

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Properties("User ID") = "me"
objConnection.Properties("Password") = "password"

objConnection.Open "LDAP Provider"

Set objCommand = CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnection

objCommand.CommandText = "SELECT name FROM
'LDAP://server:389/ou=devices,ou=network,dc=sample,dc=local' WHERE
owner='uid=me"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields.item("name").value
count = count + 1
objRecordSet.MoveNext
Loop

wscript.echo count

This code when run against the LDAP server returns the following output:

Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

null
null
null
3

I copied this code into Visual Basic 2005 Express Edition and modified to
store the data in a listbox, I did this mainly to see what was returned from
the query. As I stepped through the running code I received no errors, but
when I attempted to view what was stored in the objRecordset object it told
me 'Children could not be evaluated'. Yet it returns the correct number of
objects each time, just as null's.

Second when I attempt to use actualy attributes such as CN, OU, DN things of
that nature I get a type mismatch error like the following:

Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Users\jeffpatton\Desktop\AD Migration Scripts\list2.vbs(16, 5) Microsoft
VBSc
ript runtime error: Type mismatch

At one point I thought I was connecting to the objects but was getting back
a collection so I attempted to query for everything but only display the
field I wanted such as CN, this yieds the following error:

Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Users\jeffpatton\Desktop\AD Migration Scripts\list2.vbs(16, 5)
ADODB.Fields:
Item cannot be found in the collection corresponding to the requested name
or or
dinal.

I feel that I should be getting back at least the CN or OU but nothing
appears to work and it's been very frustrating. I have googled vbscript and
iplanet and basically get back a list of resumes, which does nothing for me.

If there is anyone who has some experience in working with non-ms LDAP and
vbScript that would be so helpful to me.

Thank you for your time and attention,

Jeff

Visual Studio107