Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using VBScript to Search eDirectory

800 views
Skip to first unread message

elain...@yahoo.com

unread,
Apr 12, 2006, 6:14:22 PM4/12/06
to
I have eDirectory installed on my Windows 2003. With the help of the
good people on this newsgroup I have been able to connect to and
populate my eDirectory tree.

One problem I face is that entry of a new account might already exist
and I want to test for this fact. I tried the LDAP search mechanism
below:

Option Explicit
On Error Resume Next

'ADO Constants
Const adOpenStatic = 3
Const adLockOptimistic = 3
'The value below required for the connection string to read a text
file
Const adCmdText = &H0001
Const objectExists = - 2147019886
Const failToOpenObject = - 2147016646
Const InvalidUseOfNull = 94


Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

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

objCommand.CommandText = _
"<LDAP://vancouver.nwtraders.msft/OU=Glasgow,O=GDS>;" & _
"(&(objectClass=inetorgPerson));" & _
"cn;subtree"

Set objRecordSet = objCommand.Execute

If objRecordset.EOF Then
Wscript.Echo _
"No user."
Else
Wscript.Echo "Users exist:"
While Not objRecordset.EOF
Wscript.Echo objRecordset.Fields("distinguishedName") & ": " & _
objRecordset.Fields("telephoneNumber")
objRecordset.MoveNext
Wend
End If

objConnection.Close

The code appears to function but no records are found in the recordset
(where there should be some)

I wondered if I needed connection credentials.

I have been able to use a recursive routine of my own to do the same
job but I wonder if it would be more effective to allow the serevr to
do the work.

Any help woul be gratefully received.

Thanks


@novell.com Susan Perrin

unread,
Apr 13, 2006, 8:19:43 PM4/13/06
to
Hi

You will need proper rights to read most attributes, but just for getting
some objects based on a search, anonymous should work ok. I think you want
to use adspath instead of distinguishedname and you want to make sure you
ask for the attributes you want in the ldap url. You might test with errors
on to see what's happening, and run dstrace if you have problems you don't
understand. The following works for me:

'Option Explicit
'On Error Resume Next

'ADO Constants
Const adOpenStatic = 3
Const adLockOptimistic = 3
'The value below required for the connection string to read a text file

Const adCmdText = &H0001
Const objectExists = - 2147019886
Const failToOpenObject = - 2147016646
Const InvalidUseOfNull = 94


Set objConnection = CreateObject("ADODB.Connection")

objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider", "CN=admin,o=novell",
"novell"

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

objCommand.CommandText = _
"<LDAP://localhost/O=novell>;" & _
"(&(objectClass=inetorgPerson));" & _
"ADsPath,telephoneNumber;subtree"

Set objRecordSet = objCommand.Execute

If objRecordset.EOF Then
Wscript.Echo _
"No user."
Else
Wscript.Echo "Users exist:"
While Not objRecordset.EOF

Wscript.Echo objRecordset.Fields("AdsPath")& ": " & _

0 new messages