向组中添加成员

创建组后,必须向组中添加成员。本主题说明如何向组中添加成员。

向组中添加成员的方法是:将成员的可分辨名称添加到组的成员属性。(有关 Active Directory 架构中的成员属性的详细信息,请参阅 MSDN Library(网址为 https://go.microsoft.com/fwlink/?LinkID=27252)中的主题“Member Attribute(成员属性)”。)使用 AddAddRange 方法可以做到这一点。

若要向组中添加单个成员,请使用 Add 方法将成员的可分辨名称添加到组对象的成员属性。

注意:
以下示例需要 .NET Framework 1.0 Service Pack 3 及更高版本或 .NET Framework 1.1 Service Pack 1 及更高版本。

下面的 C# 示例说明如何向组中添加单个成员。

// Bind to the group.
DirectoryEntry group = dom.Children.Find(groupDN);

// Add the user to the group.
group.Properties["member"].Add(userDN);

// Commit the changes to the group.
group.CommitChanges();

下面的 Visual Basic .NET 示例说明如何向组中添加单个成员。

' Bind to the group.
Dim group As New DirectoryEntry(groupDN)

' Add the user to the group.
group.Properties("member").Add(userDN)

' Commit the changes to the group.
group.CommitChanges()

若要一次性向组中添加多个成员,请使用 AddRange 方法将成员的可分辨名称添加到组对象的成员属性。

下面的 C# 示例说明如何向组中添加多个成员。

// Bind to the group.
DirectoryEntry group = dom.Children.Find(groupDN);

// To add multiple users to a group, use the AddRange method.
group.Properties["member"].AddRange(new string[] {userDN1, userDN2});

// Commit the changes to the group.
group.CommitChanges();

下面的 Visual Basic .NET 示例说明如何向组中添加多个成员。

' Bind to the group.
Dim group As New DirectoryEntry(groupDN)

' To add multiple users to a group, use the AddRange method.
group.Properties("member").AddRange(New String() {userDN1, userDN2})

' Commit the changes to the group.
group.CommitChanges()

另请参见

参考

PropertyValueCollection
System.DirectoryServices

概念

组管理

Send comments about this topic to Microsoft.

版权所有 (C) 2007 Microsoft Corporation。保留所有权利。