DirectoryEntry.Children 属性
使用此属性在层次结构中查找、检索或创建目录项。此属性是一个集合,它与通常的迭代功能一起,提供 Add 方法,通过该方法将节点直接添加到当前绑定到的父节点之下的集合。当向集合中添加节点时,必须指定新节点的名称以及要与该节点相关联的架构模板的名称。例如,您可能需要使用标题为“Computer”的架构在层次结构中添加新的计算机。
谁能给个此属性的ADD方法的详解呀?
如:
newEntry=entry.Children.Add(entryName,"user");  
  newEntry.UsePropertyCache=true;  
  newEntry.Properties["sAMAccountName"].Value="userName";  
  newEntry.Properties["userPrincipalName"].Value=="userName";  
  newEntry.Properties["sn"].Value="usetsn";  
  newEntry.Properties["displayName"].Value="userName";  
  newEntry.Properties["userAccountControl"].Value="66048";  
  newEntry.Properties["givenName"].Value="givename";  
能针对每行进行注释下吗?

解决方案 »

  1.   

    public static bool CreateLocalUserAccount(string userName, string password)
    {
       try
       {
          if (string.IsNullOrEmpty(userName))
            throw new ArgumentNullException("userName", "Invalid User Name.");
          if (string.IsNullOrEmpty(password))
            throw new ArgumentNullException("password", "Invalid Password.");
          DirectoryEntry directoryEntry = new DirectoryEntry("WinNT://" +
          Environment.MachineName + ",computer");
          bool userFound = false;
          try
          {
             if (directoryEntry.Children.Find(userName, "user") != null)
               userFound = true;
          }
          catch
          {
             userFound = false;
          }
          if (!userFound)
          {
             DirectoryEntry newUser = directoryEntry.Children.Add(userName, "user");
             newUser.Invoke("SetPassword", new object[] { password });
             newUser.Invoke("Put", new object[] { "Description", "Application Pool User Account" });
             newUser.CommitChanges();
             newUser.Close();
          }
       }
       catch (Exception ex)
       {
            throw new Exception(ex.Message, ex);
       }
       return true;
    }
      

  2.   

    能针对每行进行注释下吗?
    谁能给个此属性的ADD方法的详解呀?