Share via


Getting a List of Objects In a Container

Getting a List of Objects In a Container

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The following example returns a list of all specified objects in specified container.

Visual Basic

'//////////////////////////////////////////////////////////////////////
' Function: getObjectList()
' Purpose:  Returns a list of all specified objects in specified container
'
' Input:    szUserName:           Admin Username
'           szUserPwd:            Admin pwd
'           szConnString:         LDAP path to the container
'           szObjectType:         Type of objects to list
'           szObjectList:         List of object
'
' Output:   getObjectList:        Contains Error code (if any)
'
' Note:  In order for this example to function correctly, it may be necessary to include
' references to the following libraries: Active DS Type Library, Microsoft CDO for
' Exchange Management Library, Microsoft Cluster Service Automation Classes,
' Microsoft CDO for Windows 2000 Library.
'//////////////////////////////////////////////////////////////////////
Public Function getObjectList(ByVal szUserName As String, _
                              ByVal szUserPwd As String, _
                              ByVal szConnString As String, _
                              ByVal szObjectType As String, _
                              ByRef szObjectList As String) As Integer

    Dim objLdap As IADsOpenDSObject
    Dim objOrgs As IADsContainer
    Dim objObject As IADs

    On Error GoTo errhandler

    ' Build the ldap connection string.

    Set objLdap = GetObject("LDAP:")

    ' Enumerate though each policy object and get it's name.

    Set objOrgs = objLdap.OpenDSObject(szConnString, _
                                       szUserName, _
                                       szUserPwd, _
                                       ADS_SECURE_AUTHENTICATION)

    szObjectList = ""

    If szObjectType <> "" Then
        objOrgs.filter = Array(szObjectType)
    End If

    For Each objObject In objOrgs
        If szObjectList <> "" Then
            szObjectList = szObjectList + ";" + Mid(objObject.Name, 4)
        Else
            szObjectList = Mid(objObject.Name, 4)
        End If
    Next

    If szObjectList = "" Then
        szObjectList = "No Objects"
    End If
    szObjectList = UCase(szObjectList)

    getObjectList = 0

    ' Clean up.
    Set objLdap = Nothing
    Set objOrgs = Nothing
    Set objObject = Nothing

    Exit Function

    ' Error handling.
errhandler:

    szObjectList = "No Objects"
    ' Implement error logging here.
    getObjectList = 1
    Set objLdap = Nothing
    Set objOrgs = Nothing
    Set objObject = Nothing

    Exit Function

End Function

Send us your feedback about the Microsoft Exchange Server 2003 SDK.

Build: June 2007 (2007.618.1)

© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.