Here's some code:
DirectorySearcher searcher = new DirectorySearcher();
searcher.Filter = "(&(objectClass=user)(sAMAccountName=" + lstUsers.SelectedItem.Text + "))";
SearchResult result = searcher.FindOne();
Within result.Properties["useraccountcontrol"] will be an item which will give me a value depending on the state of the account. For instance, a value of 66050 means I'm dealing with: A normal account; where the password does not expire;which has been disabled. Explanation here.
What's the most concise way of finding out if my value "contains" the AccountDisable flag (which is 2)
Thanks in advance!
Convert.ToBoolean((int)result.Properties["useraccountcontrol"] & 0x0002)
Translated from a current code base here, it should work...
enum AccountFlags
{
Script = (1<<0),
AccountDisable = (1<<1),
// etc...
}
if( ((int)result.Properties["useraccountcontrol"]) & AccountFlags.AccountDisable > 0 )
{
// Account is Disabled...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With