比如:我建立一个ls组,想要通过程序把用户xiaoming添加到组ls中。请问应当怎么处理?

解决方案 »

  1.   

    DirectoryEntry   entry=new   DirectoryEntry(OUPath,"username","password");  
      DirectoryEntry   newEntry;  
      string   entryName="cn=testuser";  
      newEntry=entry.Children.Add(entryName,"user");  
      newEntry.UsePropertyCache=true;  
      newEntry.Properties["sAMAccountName"].Value="userID";  
      newEntry.Properties["userPrincipalName"].Value="userID";  
      newEntry.CommitChanges();http://topic.csdn.net/t/20030428/22/1719106.html
      

  2.   

    网上有个ADHelper的类!!! 你把他下载下来  里面的方法很多了  基本上就够你用了 即使不够用!也能让你清楚活动目录编程了~~~
      

  3.   

        public static void MoveUserToGroup(string UserName, string GroupName)
            {
                DirectoryEntry oGroup = SearchGroupPath(GroupName);
        
                DirectoryEntry oUser = SearchUserPath(UserName);
                //Add the user to the group via the invoke method
                oGroup.Invoke("Add", new Object[] { oUser.Path.ToString() });            oGroup.CommitChanges();            oGroup.Close();
                oUser.Close();
            }
      

  4.   


    什么意思??        public static DirectoryEntry SearchGroupPath(string GroupName)
    {
                
    DirectoryEntry de = GetDirectoryObject();
                 try
                 {
                     //create instance fo the direcory searcher
                     DirectorySearcher deSearch = new DirectorySearcher();                 //set the search filter
                     deSearch.SearchRoot = de;
                     //deSearch.PropertiesToLoad.Add("cn");
                     deSearch.Filter = "(&(objectClass=group)(cn=" + GroupName + "))";                 //get the group result
                     SearchResult results = deSearch.FindOne();                 //if the group is valid, then continue, otherwise return a blank dataset
                     if (results != null)
                     {
                         //create a link to the group object, so we can get the list of members
                         //within the group                     return results.GetDirectoryEntry();
                     }
                     else
                     {
                         return null;
                     }
                 }
                 catch (Exception ex)
                 {
                     throw new Exception(ex.Message);
                 }
    }
      public static DirectoryEntry SearchUserPath(string UserName)
            {
                //create an instance of the DirectoryEntry
                DirectoryEntry de = GetDirectoryObject();
                //create instance fo the direcory searcher
                DirectorySearcher deSearch = new DirectorySearcher();            deSearch.SearchRoot = de;
                //set the search filter
                deSearch.Filter = "(&(objectClass=user)(cn=" + UserName + "))";
                deSearch.SearchScope = SearchScope.Subtree;
                try
                {
                    //find the first instance
                    SearchResult results = deSearch.FindOne();                    de = new DirectoryEntry(results.Path, _ADUser, _ADPassWord, AuthenticationTypes.Secure);
                        //if so then return the DirectoryEntry object
                        return de;
                }
                catch
                {
                    return null;
                }
            }