How to programmatically add members to a group

Source: Internet
Author: User
Tags bind ldap
Programming


Profile
This article discusses how to use Active Directory Service interfaces (ADSI) 2.0 and VBScript to programmatically add members to a specific group in the Site Server 3.0 Membership Directory 。


More information
Follow these steps to add a member to a group in Site Server 3.0:


Bind the group to which you want to add users.


Creates a new MemberOf object based on the common name (CN) of the user to be added to the group (the member must exist).


Set the Memberobject property to the distinguished name (DN) of the user you want to add.


The following code demonstrates 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'll be stored in the
Group
Set adsMemberOf = adsgroup.create ("memberof", STRUSERCN)
' Add the path to the ' user and store it ' 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

Reference
Active Directory Service Interfaces version 2 is located in Microsoft Developer network LIBRARY/SDK documentation/platform SDK/NETW Orking and distributed Services.

Keywords: prodsitesrv3
Question type:
Problem type technology:




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.