How do I programatically determine the enabled or disabled status of AD accounts

  • Thread starter Thread starter dave
  • Start date Start date
D

dave

How do I programatically determine the enabled or
disabled status of AD accounts?

I have queried the userAccountControl key, but all I get
back is an int, and it seems to be the same for enabled
or disabled accounts. Please help.

I have read the following article:

http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/sds/sds/enabling_and_disabling_the_user_account.asp

The following code example shows how to enable a user
account.

[C#]
DirectoryEntry usr =
new DirectoryEntry("LDAP://CN=New
User,CN=users,DC=fabrikam,DC=com");
int val = (int) usr.Properties
["userAccountControl"].Value;
usr.Properties["userAccountControl"].Value = val &
~ADS_UF_ACCOUNTDISABLE;
usr.CommitChanges();
The following code example shows how to disable a user
account.

[C#]
DirectoryEntry usr =
new DirectoryEntry("LDAP://CN=Old
User,CN=users,DC=fabrikam,DC=com");
int val = (int) usr.Properties
["userAccountControl"].Value;
usr.Properties["userAccountControl"].Value = val |
ADS_UF_ACCOUNTDISABLE;
usr.CommitChanges();
 
dave said:
How do I programatically determine the enabled or
disabled status of AD accounts?

I have queried the userAccountControl key, but all I get
back is an int, and it seems to be the same for enabled
or disabled accounts. Please help.

Should be different, what value did you get back?
Wily.
 
OK, I'm an idiot, 512 for enabled accounts and 514 for
disabled, don't bother replying as I have fixed my own
stupidity. LOL.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top