1
我正在使用C#Windows應用程序。我想在該項目中實現Active Directory身份驗證。但我不知道如何在Active Directory中創建一個組。在Active Directory中創建新組
如何通過c#代碼在Active Directory中創建新組?
我正在使用C#Windows應用程序。我想在該項目中實現Active Directory身份驗證。但我不知道如何在Active Directory中創建一個組。在Active Directory中創建新組
如何通過c#代碼在Active Directory中創建新組?
如果您使用的是.NET 3.5或更高版本,則應該查看System.DirectoryServices.AccountManagement
(S.DS.AM)命名空間。在這裏閱讀全部內容:
基本上,你需要建立要內部創建的組容器上的主體上下文,然後創建一個新的GroupPrincipal
,設置它的屬性,並保存它:
// set up domain context and binding to the OU=TechWriters organizational unit in your company
using(PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "YourCompany", "ou=TechWriters,dc=yourcompany,dc=com"))
{
// create a new group principal, give it a name
GroupPrincipal group = new GroupPrincipal(ctx, "Group01");
// optionally set additional properties on the newly created group here....
// save the group
group.Save();
}
T他新推出的S.DS.AM讓玩家可以輕鬆地與AD中的用戶和羣體玩耍!