Directory Services

Associating Users With Groups

Changing group membership for users is a common system administration task, and simple to accomplish using ADSI.

Adding a User to a Group

To add users to groups, call the Add method of the group object, passing the ADsPath of the user to add. The following code example adds the user "adsitest" to the group "Administrators".

Dim myGroup
Dim myUser

On Error Resume Next

Set myGroup = GetObject("WinNT://mymachine/Administrators,group")
Set myUser = GetObject("WinNT://mymachine/adsitest,user")

myGroup.Add(myUser.ADsPath)

Be aware that unlike setting properties, no call to SetInfo is required to commit group membership changes to the directory.

Removing a User from a Group

To remove users from groups, call the Remove method of the group object, passing the ADsPath of the user to remove. The following code example removes the user "adsitest" from the group "Administrators".

Dim myGroup
Dim myUser

On Error Resume Next

Set myGroup = GetObject("WinNT://mymachine/Administrators,group")
Set myUser = GetObject("WinNT://mymachine/adsitest,user")

myGroup.Remove(myUser.ADsPath)

Again, be aware that no call to SetInfo is required.