DirectoryEntry entry=new DirectoryEntry(addpath,"username","password");
DirectoryEntry newEntry;newEntry=entry.Children.Add(entryName,"organizationalUnit");
newEntry.UsePropertyCache=true;
newEntry.Properties["description"].Value="testOU";
newEntry.CommitChanges();

解决方案 »

  1.   

    其中addpath为你要在添加的OU的父目录
      

  2.   

    在OU下添加用户(user),及移除用户.
    怎么写?
      

  3.   

    添加用户:
    DirectoryEntry entry=new DirectoryEntry(OUPath,(string)conns["username"],(string)conns["password"]);
    DirectoryEntry newEntry;
    string entryName="cn=userName";
    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";
    newEntry.CommitChanges();
      

  4.   

    移除用户:
    DirectoryEntry myds=new DirectoryEntry(OUPath,"username","password");
    foreach(DirectoryEntry tempEntry in myds.Children)
    {
        if(tempEntry.SchemaClassName.ToString() == "user")
    {
    if(tempEntry.Properties["sAMAccountName"].Value.ToString().ToLower()=="userID")
        {
    myds.Children.Remove(tempEntry);
    myds.CommitChanges();
          }
              }
    }
      

  5.   

    我在用newEntry=entry.Children.Add(entryName,"organizationalUnit");时
    提示"不支持此接口 "
    具体程序如下:
    DirectoryEntry OldUser,NewUser;
    DirectoryEntry UserEntry=new DirectoryEntry("WinNT://compueter.com/mycomputer","username","password");
    NewUser = UserEntry.Children.Add ("testOU","organizationalUnit");
    NewUser.CommitChanges();但是:如果是add user就是对的如:NewUser = UserEntry.Children.Add ("testOU","user");我错在哪?
      

  6.   

    你最好用LDAP;
    AddPath用LDAP指向一个OU
      

  7.   

    或"LDAP://Domainname/"将在根目录下建立新的OU
      

  8.   

    用LDAP//Domainname和
    (DirectoryEntry)UserEntry.Invoke("Create",new object[2]{"organizationalUnit", "ou=testOU"});真的可以。(不过用Add方法不行,奇怪)
    在活动目录中怎么读取email地址?(一个exchange2000)
      

  9.   

    你再add方法中,应该这样:
    NewUser = UserEntry.Children.Add ("ou=testOU","organizationalUnit");
    是"ou=testOU"
    ok?
    关于email,你可以将DirectoryEntry对象的所有属性打出来看看
      

  10.   

    对了。ok了.
    我用模拟身份验证,就不用username,password.
    在webconfig中写:
       <identity impersonate="true"/>
    不过。好象不能社密码。我再去试一下.
      

  11.   


    怎样修改密码?(用ldap)
    DirectoryEntry newEntry;
    DirectoryEntry UserEntry=new DirectoryEntry ("LDAP://OU=TESTOU,DC=dev,DC=com");
     OldUser = UserEntry.Children.Find  (UserAccount,"User");
    OldUser.Invoke ("SetPassword",new Object[]{Password});
    OldUser.CommitChanges();
    怎不行?