//应用
using System.DirectoryServices;
using System.DirectoryServices.ActiveDirectory;
using System.DirectoryServices.Protocols;
using System.DirectoryServices;
using System.DirectoryServices.ActiveDirectory;
using System.DirectoryServices.Protocols;
//检查是否xxxx公司的AD
public bool IsUserValid(string name, string pwd)
{
string logName = "";
string fullName = @"xxxxx\";
try
{
DirectoryEntry objDE = new DirectoryEntry("LDAP://192.168.6.6", fullName + name, pwd, AuthenticationTypes.ServerBind);
//修改密码..
// objDE.Invoke("ChangePassword",new object[]{"ccc","fff"});
//();
DirectorySearcher mySearcher = new DirectorySearcher(objDE);
mySearcher.Filter = ("(SAMAccountName=" + name + ")");
SearchResult s = mySearcher.FindOne();
if (s != null)
{
return true;
}
else
{
return false;
}
}
catch (Exception)
{
return false;
}
}