共用方式為


將成員新增至群組

在建立群組時,必須新增成員到群組。此主題說明如何新增成員到群組。

藉由新增成員的辨別名稱到群組的成員屬性,可以將成員加入群組。(如需 Active Directory 結構描述中成員屬性的詳細資訊,請參閱 MSDN Library (網址為 https://go.microsoft.com/fwlink/?LinkID=27252 (本頁面可能為英文)) 中的<成員屬性>主題)。這可以使用 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.

Copyright © 2007 by Microsoft Corporation.All rights reserved.