ADO querry using "ADsDSOObject" in VBScript 
Author Message
 ADO querry using "ADsDSOObject" in VBScript

Hi,

I am trying to extract a group membership list of my domain using
VBScript.  I want to use ADO because it is much more efficient than
doing a "GetObject".  The issue seem to be that when a variant is
return in the record set VBScript can not deal with it.  Is this a
know limitation?  Is there any work around?

Thanks

Presently this code will complain on LBound and UBound but get the
right value if On error resume next is there.

The worst is that I can't get any values from the multie value group
list.

Const ADS_SCOPE_SUBTREE = 2
Const adVariant = 12

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select name, member from
'LDAP://CN=Users,DC=oag-bvg,DC=gc,DC=ca' where objectClass='group'"

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
  On error resume next
  For i = 0 To objRecordSet.Fields.Count - 1
      'For Multi Value attribute
       If objRecordSet.Fields(i).Type = adVariant Then
          Wscript.Echo objRecordSet.Fields(i).Name & " = "
          For j = LBound(objRecordSet.Fields(i).Value) To
UBound(objRecordSet.Fields(i).Value)
              Wscript.Echo "objRecordSet.Fields.Count ->" & i & "  
UBound(objRecordSet.Fields(i).Value) ->" & j
              Wscript.Echo objRecordSet.Fields(i).Item(j)
          Next
       Else
          'For Single Value attribute
           Wscript.Echo objRecordSet.Fields(i).Name & " = " &
objRecordSet.Fields(i).Value
       End If
  Next
  objRecordSet.MoveNext
Loop



Sat, 27 Nov 2004 21:48:35 GMT  
 ADO querry using "ADsDSOObject" in VBScript

Quote:

> I am trying to extract a group membership list of my domain using
> VBScript.  I want to use ADO because it is much more efficient than
> doing a "GetObject".  The issue seem to be that when a variant is
> return in the record set VBScript can not deal with it.  Is this a
> know limitation?  Is there any work around?

This should do it:

'----------------------------------
Do Until objRecordSet.EOF
  For i = 0 To objRecordSet.Fields.Count - 1
    'For Multi Value attribute
    If objRecordSet.Fields(i).Type = adVariant And Not
IsNull(objRecordSet.Fields(i).Value) Then

      arrField = objRecordSet.Fields(i)

      For Each strItem In arrField
        Wscript.Echo objRecordSet.Fields(i).Name & " = " & strItem
      Next

      ' alternativly
      'For j = 0 To Ubound(arrField)
      '  Wscript.Echo objRecordSet.Fields(i).Name & " = " & arrField(j)
      'Next

    Else
      'For Single Value attribute
      Wscript.Echo objRecordSet.Fields(i).Name & " = " &
objRecordSet.Fields(i).Value
    End If
  Next
  objRecordSet.MoveNext
Loop

Here is yet another way of doing it:

'----------------------------------
Do Until objRecordSet.EOF
  For i = 0 To objRecordSet.Fields.Count - 1

    arrField = objRecordSet.Fields(i)

    'For Multi Value attribute
    If IsArray(arrField) Then
      For Each strItem In arrField
        Wscript.Echo objRecordSet.Fields(i).Name & " = " & strItem
      Next

      ' alternativly
      'For j = 0 To Ubound(arrField)
      '  Wscript.Echo objRecordSet.Fields(i).Name & " = " & arrField(j)
      'Next

    Else
      'For Single Value attribute
      Wscript.Echo objRecordSet.Fields(i).Name & " = " &
objRecordSet.Fields(i).Value
    End If
  Next
  objRecordSet.MoveNext
Loop

--
torgeir



Sun, 28 Nov 2004 03:58:09 GMT  
 ADO querry using "ADsDSOObject" in VBScript
Tha sample code works perfectly.

Thanks

Quote:


> > I am trying to extract a group membership list of my domain using
> > VBScript.  I want to use ADO because it is much more efficient than
> > doing a "GetObject".  The issue seem to be that when a variant is
> > return in the record set VBScript can not deal with it.  Is this a
> > know limitation?  Is there any work around?

> This should do it:

> '----------------------------------
> Do Until objRecordSet.EOF
>   For i = 0 To objRecordSet.Fields.Count - 1
>     'For Multi Value attribute
>     If objRecordSet.Fields(i).Type = adVariant And Not
> IsNull(objRecordSet.Fields(i).Value) Then

>       arrField = objRecordSet.Fields(i)

>       For Each strItem In arrField
>         Wscript.Echo objRecordSet.Fields(i).Name & " = " & strItem
>       Next

>       ' alternativly
>       'For j = 0 To Ubound(arrField)
>       '  Wscript.Echo objRecordSet.Fields(i).Name & " = " & arrField(j)
>       'Next

>     Else
>       'For Single Value attribute
>       Wscript.Echo objRecordSet.Fields(i).Name & " = " &
> objRecordSet.Fields(i).Value
>     End If
>   Next
>   objRecordSet.MoveNext
> Loop

> Here is yet another way of doing it:

> '----------------------------------
> Do Until objRecordSet.EOF
>   For i = 0 To objRecordSet.Fields.Count - 1

>     arrField = objRecordSet.Fields(i)

>     'For Multi Value attribute
>     If IsArray(arrField) Then
>       For Each strItem In arrField
>         Wscript.Echo objRecordSet.Fields(i).Name & " = " & strItem
>       Next

>       ' alternativly
>       'For j = 0 To Ubound(arrField)
>       '  Wscript.Echo objRecordSet.Fields(i).Name & " = " & arrField(j)
>       'Next

>     Else
>       'For Single Value attribute
>       Wscript.Echo objRecordSet.Fields(i).Name & " = " &
> objRecordSet.Fields(i).Value
>     End If
>   Next
>   objRecordSet.MoveNext
> Loop



Sun, 28 Nov 2004 21:53:06 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Best Pascal Compiler for Win2K

2. Access to "Special Folders" using VBScript

3. automating "Move to Folder..." using VBscript

4. Specifying "Current" Jet Database Using ADO

5. HELP! - Disconnect from Internet

6. !!! help - date query and empty foreign key insertion

7. Memo in DBGrid

8. Using "Edit With" from VBScript

9. Access to "Special Folders" using VBScript

10. Using "Implements" in VBScript

11. *"*-.,._,.-*"* I"LL TRADE VISUAL C++ FOR VBASIC *"*-.,_,.-*"*

12. ADO Results "randomly" not being returned

 

 
Powered by phpBB® Forum Software