使用C#,你怎么检查,如果一个计算机帐户在Active Directory中被禁用? [英] Using C#, how do you check if a computer account is disabled in active directory?
本文介绍了使用C#,你怎么检查,如果一个计算机帐户在Active Directory中被禁用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你怎么检查,如果一个计算机帐户是用C#/ Active Directory中禁用的。NET
How do you check if a computer account is disabled in Active Directory using C#/.NET
推荐答案
试试这个:
class Program
{
static void Main(string[] args)
{
const string ldap = "LDAP://your-ldap-server-here";
using (DirectoryEntry conn = new DirectoryEntry(ldap))
{
using (DirectorySearcher searcher = new DirectorySearcher(conn))
{
searcher.Filter = "(|(samAccountName=userA)(samAccountName=userB))";
searcher.PropertiesToLoad.Add("samAccountName");
searcher.PropertiesToLoad.Add("userAccountControl");
using (SearchResultCollection results = searcher.FindAll())
{
foreach (SearchResult result in results)
{
int userAccountControl = Convert.ToInt32(result.Properties["userAccountControl"][0]);
string samAccountName = Convert.ToString(result.Properties["samAccountName"][0]);
bool disabled = ((userAccountControl & 2) > 0);
Console.WriteLine("{0} ({1:x}) :: {2}", samAccountName, userAccountControl, disabled);
}
}
}
}
Console.ReadLine();
}
}
userAccountControl的
的第二位为1,如果账号被禁用。
The second bit of userAccountControl
will be 1 if the account is disabled.
这篇关于使用C#,你怎么检查,如果一个计算机帐户在Active Directory中被禁用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文