2011-07-31 89 views

回答

3

您可以通過添加引用 「System.DirectoryServices.dll程序」 然後你可以使用一個DirectoryEntry使用ADSI(Active Directory服務接口)像這樣:

public static void AddUserToGroup(string userDistinguishedname, string groupDistinguishedName) { 
    DirectoryEntry group = new DirectoryEntry("LDAP://ldap.mydomain.com/" + groupDistinguishedName); 
    DirectoryEntry user = new DirectoryEntry("LDAP://ldap.mydomain.com/" + userDistinguishedname); 
    group.Username = "Administrator"; 
    group.Password = "myAdminPassword"; 

    using (group) //group is your DirectoryEntry for group 
    { 
     //member if your user DirectoryEntry 
     group.Invoke("Add", new string[] { user.Path }); 
    } 
} 

希望這有助於

相關問題