Platform SDK: Exchange Server

About the DLUpdate Sample

This section briefly describes the files that comprise the DLUpdate sample and a few of the important ADSI methods and properties that the sample uses to access DLs.

Sample Files

Files Description
Global.asa contains the Application and Session start and end routines.
Ads.inc Contains constants and subroutines for handling the ADSI objects.
DlMaintenance.asp Displays information about the selected DL.
DlProperties.asp Displays an interface for adding a DL or modifying the selected DL.
Handlecmds.asp Contains routines for handling application messages.
Logon.asp Displays two frames, one for the interface and the other for passing messages and commands.
SelDN.asp Contains routines to select and add DL members.
SelExchServer.asp Contains a routine to select an Exchange server.
*.inc Other INC files containing global constants, functions, and subroutines.
*.gif GIF-format graphics files.

ADSI Methods and Properties

The DLUpdate sample contains the following subroutines in the Ads.inc file:

Sub ADS_GetDL()

This subroutine gets the passed page of DLs and sets the DL's display name and aliases. It contains the following code (with some minor formatting tweaks to fit it on the page):

Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=ADSDSOObject"

Set rsDL = CreateObject("ADODB.Recordset")
rsDL.PageSize = mcADS_RS_PAGE_SIZE

strQuery = "<" & strADsPath(gstrNONE) & ">" _
         & "(&(" & mstrADS_COL_DISP_NAME & "=" _
         & strLDAPSearch(pstrSelCriteria) _
         & "*)" & "(objectClass=" & gstrADS_CLASS_DL & "));" _
         & mstrADS_COL_DISP_NAME & "," & mstrADS_COL_ADS_PATH _
         & ";OneLevel"

rsDL.Open strQuery, conn

The first two lines create and open a connection to the ADO data source provider, ADSDSOObject, which is the OLE DB data source for ADSI. This data source includes the LDAP directory, which contains the Exchange address book.

The next two lines create a recordset object to hold the DLs returned by the subsequent Open method. The PageSize property restricts the number of DLs returned to a constant, mcADS_RS_PAGE_SIZE, which is set to 100. By default, ADSI can return a maximum of 100 users in a single query. This value is set in the Exchange administration applet's LDAP (Directory) Default Site Settings, Protocols, Search property tab.

The rsDL variable now holds a recordset of DLs.

Sub ADS_AddDLMembers()

This subroutine adds the names in the passed collection of ADs paths to the DL. It contains the following code (with some minor formatting tweaks to fit it on the page):

Set recipient = GetObject(pstrADsPathRecipient)
For irgstrADsPathMembers = Lbound(ADS_rgstrADsPathMembers) To _
                           Ubound(ADS_rgstrADsPathMembers)
     Set recipientDLMember = __
      GetObject(ADS_rgstrADsPathMembers(irgstrADsPathMembers))

    recipient.Add recipientDLMember.ADsPath
Next

The first line uses the DL path that's passed as an input parameter to the subroutine to obtain the recipient object for the DL. The second line enumerates through the list of new members for the DL. The third line adds each member to the DL.

Adding a Known User to a Known DL

The following code demonstrates a simple case of adding a user to a DL. It adds the mailbox account alias DougS to the distribution list alias ExchSDK. You can see how an LDAP path is built by examining the private subroutine strADsPath() in the Ads.inc file. This example uses the IADsGroup interface on the ADSI object returned by the ADSI provider using the GetObject routine.

DLpath = "LDAP://Spock/cn=ExchSDK,cn=Recipients,ou=Earth,o=Federation"
User="LDAP://Spock/cn=DougS,cn=Recipients,ou=Earth,o=Federation"

Set DL = GetObject(DLpath)
if DL.IsMember(User) Then  'IADsGroup IsMember method
  '  response accordingly
Else
 DL.Add(User)              ' IADsGroup Add method
End If

Set DL = Nothing
Set User = Nothing

You can use the Active Directory Browser (Adsvw.exe) to browse the LDAP directory on your server. If you don't have this utility, you can get it from the Microsoft ADSI SDK at the ADSI Web page http://www.microsoft.com/adsi.