Advertisement
Guest User

Untitled

a guest
May 4th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1.  public static void AddUserToGroup(string userDistinguishedname, string groupDistinguishedName)
  2.         {
  3.             DirectoryEntry group = new DirectoryEntry("LDAP://ldap.mydomain.com/" + groupDistinguishedName);
  4.             DirectoryEntry user = new DirectoryEntry("LDAP://ldap.mydomain.com/" + userDistinguishedname);
  5.             group.Username = "Administrator";
  6.             group.Password = "myAdminPassword";
  7.  
  8.             using (group) //group is your DirectoryEntry for group
  9.             {
  10.                 //member if your user DirectoryEntry
  11.                 group.Invoke("Add", new string[] { user.Path });
  12.             }
  13.         }
  14.  
  15.  
  16.         public static void RemoveUserFromGroup(string userDistinguishedname, string groupDistinguishedName)
  17.         {
  18.             DirectoryEntry group = new DirectoryEntry("LDAP://ldap.mydomain.com/" + groupDistinguishedName);
  19.             DirectoryEntry user = new DirectoryEntry("LDAP://ldap.mydomain.com/" + userDistinguishedname);
  20.             group.Username = "Administrator";
  21.             group.Password = "myAdminPassword";
  22.  
  23.  
  24.             using (group) //group is your DirectoryEntry for group
  25.             {
  26.                 //member if your user DirectoryEntry
  27.                 group.Invoke("Remove", new string[] { user.Path });
  28.             }
  29.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement