111,093
社区成员




using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DirectoryEntry entry = new DirectoryEntry("LDAP://XYAMC", "fax-gl", "Xyjj2014", AuthenticationTypes.Secure);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = ("(objectClass=user)"); //这行的 objectClass=user 看不懂,我猜这行代码是获取域用户名。Filter属性还可以等于其他什么条件吗?
System.IO.StreamWriter sw = new System.IO.StreamWriter(@"d:\1.txt");
foreach (SearchResult resEnt in mySearcher.FindAll())
{
string s = resEnt.GetDirectoryEntry().Properties["sAMAccountName"].Value.ToString(); //这行代码看不懂
sw.WriteLine(s);
}
sw.WriteLine("=====我是分割线=====");
sw.WriteLine("总数量: " + mySearcher.FindAll().Count);
sw.Flush();
sw.Close();
sw.Dispose();
}
}
}