How to Programmatically Add Members to Groups

ID: Q192782


The information in this article applies to:


SUMMARY

This article describes how to programmatically add a member to a specific group in Site Server 3.0 Membership Directory using Active Directory Service Interfaces (ADSI) 2.0 and VBScript.


MORE INFORMATION

To add a member to a group in Site Server 3.0, perform the following steps:

  1. Bind to the group in which you want to add the user.


  2. Create a new MemberOf object based on the Common Name (CN) of the user that you wish to add to the group (the member must exist).


  3. Set the MemberObject attribute to be the Distinguished Name (DN) of the user you wish to add.


The following code illustrates this procedure:


   Dim adsMemberOf
   Dim adsGroup
   Dim strLdapSrv
   Dim strMemberPath, strUserCn, strUserDn, _
   strGroupDn, strAdmin, strAdminPwd

   strLdapSrv       = "LDAP://localhost:5292"
   strMemberPath    = ",ou=Members,o=Microsoft"
   strUserCn        = "cn=JohnDoe"
   strUserDn        = strUserCn + strMemberPath
   strGroupDn       = strLdapSrv +
   "/o=Microsoft/ou=Groups/cn=Public"
   strAdmin         = "cn=Administrator,ou=Members,o=Microsoft"
   strAdminPwd      = "password"

   'Bind to the specific group using Administrator credentials
   Set adsGroup = GetObject("LDAP:")
   Set adsGroup = adsGroup.OpenDSObject(strGroupDn, strAdmin, _
                                    strAdminPwd, CLng(0))

   'Create the new 'memberOf' object that will be stored in the
   group
   Set adsMemberOf = adsGroup.Create("memberof", strUserCn)
   'Add the path to the user and store it in the 'memberObject'
   property
   adsMemberOf.Put "memberobject", CStr(strUserDn)

   'Flush the property cache and update the directory
    adsMemberOf.SetInfo

   'Destroy the objects
    Set adsMemberOf  = Nothing
    Set adsGroup     = Nothing
 


REFERENCES

"Active Directory Service Interfaces version 2.0" located in the Microsoft Developer Network Library/SDK Documentation/Platform SDK/Networking and Distributed Services.

Additional query words: kbDSupport


Keywords          : prodsitesrv3 
Version           : WINNT: 3.0
Platform          : winnt 
Issue type        : kbhowto 

Last Reviewed: July 15, 1999