访问AD的代码using System.DirectoryServices;DirectoryEntry root = new DirectoryEntry("LDAP://vacation.com/dc=vacation,dc=com");DirectorySearcher scr = new DirectorySearcher(root);
scr.Filter="(sAMAccountName=xxf)";
scr.PropertiesToLoad.Add("displayName");
scr.PropertiesToLoad.Add("department");SearchResult sr = scr.FindOne();
ret[0]=sr.Properties["displayName"][0].ToString();
ret[1]=sr.Properties["department"][0].ToString();

解决方案 »

  1.   

    #region 获取Domain中的User列表,返回ArrayList
    public static ArrayList GetDomainUser()
    {
             ArrayList UserList = new ArrayList();
    String strPath="LDAP://RootDSE";
    DirectoryEntry ent = new DirectoryEntry(strPath);
    String str = ent.Properties["defaultNamingContext"][0].ToString();
    DirectoryEntry domain = new DirectoryEntry("LDAP://"+str);
    foreach(DirectoryEntry child in domain.Children) 
    {  
      foreach(DirectoryEntry Nodes in child.Children)
      {
       string strName =Nodes.Name.Substring(3);
       switch (Nodes.SchemaClassName) 
        {
    case "user" :
    UserList.Add(strName);
    break;
        }
      }

             }
    return UserList;
     }
    #endregion//其中RootDSE为默认的目录服务器
    //defaultNamingContext获取当前所在域