HOWTO: Speed Up ADSI Group & Dist. List Membership Checks

ID: Q192950

The information in this article applies to:

SUMMARY

In some providers, the ADSI groupobject.IsMember(memberADsPath) method is implemented to perform membership checks by returning the entire members collection to the client and then searching for the target's path in the collection. This operation can consume a lot of time and bandwidth if the object has a large membership list, like an Exchange distribution list. You can avoid much of this overhead if the following is true:

1. You need the object only for a membership test.

2. You are using a provider that supports OLE DB.

In this case, you can do an ADO or OLE DB query and perform the search on the server. This way, only a single record is returned to the client.

The LDAP and NDS providers supplied with the ADSI runtime support this technique.

MORE INFORMATION

The following code illustrates the equivalent of the IADsGroup::IsMember method in Visual Basic using the ADO technique. You can use this code to check membership in an Exchange 5.5 distribution list. Note that this code, like the LDAP IADsGroup::IsMember method, does not check for membership in distribution lists that are members of the target distribution list.

Sample Code

   Function IsMember(strDLPath As String, strMemberPath As String _
      ) As Boolean

   ' strDLPath is ADsPath to distribution list.
   ' strMember is ADsPath to member.

   Dim conn As New ADODB.Connection
   Dim rs As ADODB.Recordset
   Dim adsMember As IADsUser

   IsMember = False

   Set adsMember = GetObject(strMemberPath)
   If adsMemeber Is Nothing Then Exit Function

   conn.Provider = "ADsDSOObject"
   conn.Open ""
   Set rs = conn.Execute( "<" + strDLPath + ">;(member=" + _
      adsMember.Get("distinguishedName") + ");ADsPath;Base")

   IsMember = Not (rs.BOF Or rs.EOF)

   End Function

REFERENCES

Microsoft Developer Network: ADSI

Additional query words:

Keywords          : kbnetwork kbADSI kbAPI kbSDKPlatform kbGrpNet 
Issue type        : kbhowto

Last Reviewed: September 26, 1998