Share via


Enumerating Users

Enumerating Users

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.

Example

This example lists the users in the "Users" container in the Active Directory. The example opens the user information in Active Directory by using Active Directory® Service Interfaces (ADSI). It then uses the IMailboxStore interface aggregated onto the ADSI user object to access information in the Exchange store.

Visual Basic

Sub List_Users(DomainName As String)

'DomainName is something like "DC=MYDOMAIN3,DC=example,DC=com"

Dim objUser As IADsUser
Dim objContainer As IADsContainer
Dim objMailbox As CDOEXM.IMailboxStore
Dim i As Long
Dim name As String

On Error GoTo Error
' get the container. Note that user information may be located in
' other organizational units.
Set objContainer = GetObject("LDAP://CN=users," + DomainName)

objContainer.Filter = Array("User")
i = 0

For Each objUser In objContainer
   name = objUser.name
   name = Right(name, Len(name) - 3)
   Set objMailbox = objUser
   If objMailbox.HomeMDB = "" Then
      Debug.Print name + "   (no mailbox)"
   Else
      Debug.Print name + "   (has mailbox)"
      Debug.Print objMailbox.HomeMDB
   End If
   i = i + 1
Next
Debug.Print "Number of users found in the DS (in the default container): " + Str(i)
GoTo Ending

Error:
   Debug.Print "Failed while displaying the users in the default container."
   MsgBox "Run time error: " + Str(Err.Number) + " " + Err.Description
   Err.Clear
Ending:

End Sub

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.