zoukankan      html  css  js  c++  java
  • AD

    在Group里面添加和删除User:

    public void AddUserToGroup(string userId, string groupName) 
    { 
        try 
        { 
            using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "COMPANY"))
            {
                GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, groupName);
                group.Members.Add(pc, IdentityType.UserPrincipalName, userId);
                group.Save();
            }
        } 
        catch (System.DirectoryServices.DirectoryServicesCOMException E) 
        { 
            //doSomething with E.Message.ToString(); 
    
        } 
    } 
    
    public void RemoveUserFromGroup(string userId, string groupName)
    {   
        try 
        { 
            using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "COMPANY"))
            {
                GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, groupName);
                group.Members.Remove(pc, IdentityType.UserPrincipalName, userId);
                group.Save();
            }
        } 
        catch (System.DirectoryServices.DirectoryServicesCOMException E) 
        { 
            //doSomething with E.Message.ToString(); 
    
        }
    }
    
  • 相关阅读:
    新式类、经典类与多继承
    实现抽象类之方式二
    实现抽象类之方式一
    re模块
    28个高频Linux命令
    Git使用教程
    编程语言介绍
    编码
    进制
    操作系统简史
  • 原文地址:https://www.cnblogs.com/johnsmith/p/3246240.html
Copyright © 2011-2022 走看看