Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista Tutorial - working LDAP query, well almost.. 800A000D

Reply
 
Old 06-19-2009   #1 (permalink)
Sander
Guest


 
 

working LDAP query, well almost.. 800A000D

Hello all,

The following script should get 2 properties form the Administrator user:
"sAMAccountName" and "description".
It does display the sAMAccountName but throws an error when it tries to
display the user description.

The code:
Set objRootDSE = GetObject("LDAP://RootDSE")
strDomainDN = objRootDSE.Get("DefaultNamingContext")
Set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"

Set objRSUserDescr = objConn.Execute("<LDAP://" & strDomainDN &
">;(&(objectClass=user)(sAMAccountName=Administrator));sAMAccountName,description;subtree")

WScript.echo objRSUserDescr.Fields(0).Value
WScript.echo objRSUserDescr.Fields(1).Value


The error:
this line: WScript.echo objRSUserDescr.Fields(1).Value
Error: Type Mismatch
Code: 800A000D

I tried CStr(objRSUserDescr.Fields(1).Value), but get the same error.
In my case, I cannot use GetObject("LDAP://" & UserDN) to get the user
description. I have to query AD directly.

Anyone an idea what goes wrong ?

thanks in advance,
Sander


My System SpecsSystem Spec
Old 06-19-2009   #2 (permalink)
James Whitlow
Guest


 
 

Re: working LDAP query, well almost.. 800A000D

"Sander" <Sander@xxxxxx> wrote in message
news:uqN2$YP8JHA.5424@xxxxxx
Quote:

> Hello all,
>
> The following script should get 2 properties form the Administrator user:
> "sAMAccountName" and "description".
> It does display the sAMAccountName but throws an error when it tries to
> display the user description.
>
> The code:
> Set objRootDSE = GetObject("LDAP://RootDSE")
> strDomainDN = objRootDSE.Get("DefaultNamingContext")
> Set objConn = CreateObject("ADODB.Connection")
> objConn.Provider = "ADsDSOObject"
> objConn.Open "Active Directory Provider"
>
> Set objRSUserDescr = objConn.Execute("<LDAP://" & strDomainDN &
> ">;(&(objectClass=user)(sAMAccountName=Administrator));sAMAccountName,description;subtree")
>
> WScript.echo objRSUserDescr.Fields(0).Value
> WScript.echo objRSUserDescr.Fields(1).Value
>
>
> The error:
> this line: WScript.echo objRSUserDescr.Fields(1).Value
> Error: Type Mismatch
> Code: 800A000D
I believe this property is an array. Change your line to:

WScript.echo Join(objRSUserDescr.Fields(1).Value, vbCrLf)




My System SpecsSystem Spec
Old 06-19-2009   #3 (permalink)
Sander
Guest


 
 

Re: working LDAP query, well almost.. 800A000D

You are right!
How silly of me (I tried IsNull IsEmpty etc, but not IsArray

It works like a charm!

lots of Thanks!
Sander


"James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message
news:%23%23d1ydP8JHA.1376@xxxxxx
Quote:

> "Sander" <Sander@xxxxxx> wrote in message
> news:uqN2$YP8JHA.5424@xxxxxx
Quote:

>> Hello all,
>>
>> The following script should get 2 properties form the Administrator user:
>> "sAMAccountName" and "description".
>> It does display the sAMAccountName but throws an error when it tries to
>> display the user description.
>>
>> The code:
>> Set objRootDSE = GetObject("LDAP://RootDSE")
>> strDomainDN = objRootDSE.Get("DefaultNamingContext")
>> Set objConn = CreateObject("ADODB.Connection")
>> objConn.Provider = "ADsDSOObject"
>> objConn.Open "Active Directory Provider"
>>
>> Set objRSUserDescr = objConn.Execute("<LDAP://" & strDomainDN &
>> ">;(&(objectClass=user)(sAMAccountName=Administrator));sAMAccountName,description;subtree")
>>
>> WScript.echo objRSUserDescr.Fields(0).Value
>> WScript.echo objRSUserDescr.Fields(1).Value
>>
>>
>> The error:
>> this line: WScript.echo objRSUserDescr.Fields(1).Value
>> Error: Type Mismatch
>> Code: 800A000D
>
> I believe this property is an array. Change your line to:
>
> WScript.echo Join(objRSUserDescr.Fields(1).Value, vbCrLf)
>
>
>
>
My System SpecsSystem Spec
Old 06-19-2009   #4 (permalink)
Richard Mueller [MVP]
Guest


 
 

Re: working LDAP query, well almost.. 800A000D

The description attribute is a strange one, because technically it is
multi-valued, even though there is never more than one value. ADO retrieves
it as an string array with one value, or a Null if there is no value
assigned.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"Sander" <Sander@xxxxxx> wrote in message
news:ucWBphP8JHA.3544@xxxxxx
Quote:

> You are right!
> How silly of me (I tried IsNull IsEmpty etc, but not IsArray
>
> It works like a charm!
>
> lots of Thanks!
> Sander
>
>
> "James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message
> news:%23%23d1ydP8JHA.1376@xxxxxx
Quote:

>> "Sander" <Sander@xxxxxx> wrote in message
>> news:uqN2$YP8JHA.5424@xxxxxx
Quote:

>>> Hello all,
>>>
>>> The following script should get 2 properties form the Administrator
>>> user: "sAMAccountName" and "description".
>>> It does display the sAMAccountName but throws an error when it tries to
>>> display the user description.
>>>
>>> The code:
>>> Set objRootDSE = GetObject("LDAP://RootDSE")
>>> strDomainDN = objRootDSE.Get("DefaultNamingContext")
>>> Set objConn = CreateObject("ADODB.Connection")
>>> objConn.Provider = "ADsDSOObject"
>>> objConn.Open "Active Directory Provider"
>>>
>>> Set objRSUserDescr = objConn.Execute("<LDAP://" & strDomainDN &
>>> ">;(&(objectClass=user)(sAMAccountName=Administrator));sAMAccountName,description;subtree")
>>>
>>> WScript.echo objRSUserDescr.Fields(0).Value
>>> WScript.echo objRSUserDescr.Fields(1).Value
>>>
>>>
>>> The error:
>>> this line: WScript.echo objRSUserDescr.Fields(1).Value
>>> Error: Type Mismatch
>>> Code: 800A000D
>>
>> I believe this property is an array. Change your line to:
>>
>> WScript.echo Join(objRSUserDescr.Fields(1).Value, vbCrLf)
>>
>>
>>
>>
>

My System SpecsSystem Spec
Old 06-19-2009   #5 (permalink)
James Whitlow
Guest


 
 

Re: working LDAP query, well almost.. 800A000D

"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:ee8CVqP8JHA.5400@xxxxxx
Quote:

> The description attribute is a strange one, because technically it is
> multi-valued, even though there is never more than one value. ADO
> retrieves it as an string array with one value, or a Null if there is no
> value assigned.
Sander, to Richard's point, you should probably do an IsArray test before
using the Join method to prevent an exception in the event that it is empty.

sDescription = objRSUserDescr.Fields("description").Value

If IsArray(sDescription) Then
sDescription = Join(sDescription, Empty)
Else
sDescription = Empty
End If

WScript.Echo sDescription


My System SpecsSystem Spec
Old 06-19-2009   #6 (permalink)
Richard Mueller [MVP]
Guest


 
 

Re: working LDAP query, well almost.. 800A000D


"James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message
news:%23ba8eAQ8JHA.1336@xxxxxx
Quote:

> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
> message news:ee8CVqP8JHA.5400@xxxxxx
Quote:

>> The description attribute is a strange one, because technically it is
>> multi-valued, even though there is never more than one value. ADO
>> retrieves it as an string array with one value, or a Null if there is no
>> value assigned.
>
> Sander, to Richard's point, you should probably do an IsArray test before
> using the Join method to prevent an exception in the event that it is
> empty.
>
> sDescription = objRSUserDescr.Fields("description").Value
>
> If IsArray(sDescription) Then
> sDescription = Join(sDescription, Empty)
> Else
> sDescription = Empty
> End If
>
> WScript.Echo sDescription
>
Agreed. Another option is to use IsNull, since if this returns False, the
value is an array. I use code similar to:
====
If IsNull(sDescription) Then
sDescription = ""
Else
For Each sItem In sDescription
sDescription = sItem
Next
End If
======
The Join function actually looks cleaner than the For Each loop I use. I
generally the the For Each loop when I deal with other multi-valued
attributes, but in this case the Join is better.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 06-19-2009   #7 (permalink)
Paul Randall
Guest


 
 

Re: working LDAP query, well almost.. 800A000D

When in doubt, have VBScript tell you about the variable. Functions
Typename and/or Vartype would have given you the array clue.

-Paul Randall

"Sander" <Sander@xxxxxx> wrote in message
news:ucWBphP8JHA.3544@xxxxxx
Quote:

> You are right!
> How silly of me (I tried IsNull IsEmpty etc, but not IsArray
>
> It works like a charm!
>
> lots of Thanks!
> Sander
>
>
> "James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message
> news:%23%23d1ydP8JHA.1376@xxxxxx
Quote:

>> "Sander" <Sander@xxxxxx> wrote in message
>> news:uqN2$YP8JHA.5424@xxxxxx
Quote:

>>> Hello all,
>>>
>>> The following script should get 2 properties form the Administrator
>>> user: "sAMAccountName" and "description".
>>> It does display the sAMAccountName but throws an error when it tries to
>>> display the user description.
>>>
>>> The code:
>>> Set objRootDSE = GetObject("LDAP://RootDSE")
>>> strDomainDN = objRootDSE.Get("DefaultNamingContext")
>>> Set objConn = CreateObject("ADODB.Connection")
>>> objConn.Provider = "ADsDSOObject"
>>> objConn.Open "Active Directory Provider"
>>>
>>> Set objRSUserDescr = objConn.Execute("<LDAP://" & strDomainDN &
>>> ">;(&(objectClass=user)(sAMAccountName=Administrator));sAMAccountName,description;subtree")
>>>
>>> WScript.echo objRSUserDescr.Fields(0).Value
>>> WScript.echo objRSUserDescr.Fields(1).Value
>>>
>>>
>>> The error:
>>> this line: WScript.echo objRSUserDescr.Fields(1).Value
>>> Error: Type Mismatch
>>> Code: 800A000D
>>
>> I believe this property is an array. Change your line to:
>>
>> WScript.echo Join(objRSUserDescr.Fields(1).Value, vbCrLf)
>>
>>
>>
>>
>

My System SpecsSystem Spec
Old 06-19-2009   #8 (permalink)
Sander
Guest


 
 

Re: working LDAP query, well almost.. 800A000D

Thats exactly what i did ;]

Thanks again James & Richard!



"James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message
news:%23ba8eAQ8JHA.1336@xxxxxx
Quote:

> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
> message news:ee8CVqP8JHA.5400@xxxxxx
Quote:

>> The description attribute is a strange one, because technically it is
>> multi-valued, even though there is never more than one value. ADO
>> retrieves it as an string array with one value, or a Null if there is no
>> value assigned.
>
> Sander, to Richard's point, you should probably do an IsArray test before
> using the Join method to prevent an exception in the event that it is
> empty.
>
> sDescription = objRSUserDescr.Fields("description").Value
>
> If IsArray(sDescription) Then
> sDescription = Join(sDescription, Empty)
> Else
> sDescription = Empty
> End If
>
> WScript.Echo sDescription
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Query LDAP to get user Telephone VB Script
How can I query LDAP in WLM? Live Mail
Why isn't this LDAP query working on the other domain in the fores VB Script
Not all users are retrieved in an LDAP query via ASP VB Script
help with LDAP query PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46