Hi,
I am not familiar with C#, so I can't help there. However, it might help to
clarify some things.
The userAccountControl attribute exposed by LDAP cannot be used to determine
if an account is locked out. This is a known bug. It also cannot be used to
lock or unlock an account. The IsAccountLocked property method exposed by
LDAP can be used to lock or unlock an account, but fails to reveal whether
an account is locked or not.
The userFlags attribute exposed by the WinNT provider is reliable. Also, the
IsAccountLocked property method exposed by the WinNT provider works. This is
one of the few cases where it might be best to use WinNT.
The lockoutTime attribute exposed by the LDAP provider represents the time
when the account was locked out. It is Integer8 (a 64-bit number), so it
must be converted to a date. If the value is zero, then the account is not
locked out. However, if it has a value, this does not mean the account is
locked out. The lockoutTime attribute is not reset to zero until the user
logs on. If the domain lockoutTime policy has not expired, the account is
still locked out, otherwise, the account is not locked but the user has not
yet logged in. You must retrieve the domain lockoutDuration attribute, add
this to the user lockoutTime, and check if the result is before or after the
current date/time.
I have VBScript program that does all of this for a specified user linked on
the page below:
http://www.rlmueller.net/IsUserLocked.htm
I assume the property methods are not available in C#, so you will be
dealing directly with the attributes. If so, the VBScript code may give you
a guide, as the underlying principals are the same. Also, Joe Richards has a
utility on his web site to find and handle locked accounts:
http://www.joeware.net
The real mystery is why the WinNT provider userFlags attribute and
IsAccountLocked property method seem to work.
--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site - http://www.rlmueller.net
--
Post by Tony TortoraI found that document last night and was checking it out this morning when I
saw your post. Everything I have found on MSDN states that LDAP is not
reliable in retrieving the IsAccountLocked status.
I created two basic users ADTest1 and ADTest2. I inspected both users and
the "userAccountControl" field is set to a value of 513. I locked the
ADTest2 user and the "userAccountControl" field still returns 513. I
located the ADTest2 object using the WinNT provider
"WinNT//mydomain/ADTest2" and the "UserFlags" field contains a value of 529.
I compared the "UserFlags" with both users and ADTest1 had a value of 513
and ADTest2 had a value 529. Bit 5 is a value of 16 and the math makes
sense. I tried to update the record with the WinNT Provider and I get an
unhandled exception error.
Antonio
Post by Marc Scheuner [MVP ADSI]Post by Antonio TortoraI am trying to read the status of the IsAccountLocked field in a user
object
Post by Marc Scheuner [MVP ADSI]Post by Antonio Tortorain the Active Directory. I am able to read the user object with the
"WinNT"
Post by Marc Scheuner [MVP ADSI]Post by Antonio TortoraProvider. The WinNT provider returns a collection of 24 items. I
suspect
Post by Marc Scheuner [MVP ADSI]Post by Antonio Tortorathe field I want is contained within the UserFlags.
Yes, almost :-) The LDAP property is called "userAccountControl", and
contains a number of flags for the user object.
DirectoryEntry deUser = new
DirectoryEntry("LDAP://cn=Tony,cn=Users,dc=yourcompany,dc=com");
int iFlags = (int)deUser.Properties["userAccountControl"].Value;
Check out the ADS_USER_FLAG_ENUM enumeration in MSDN for the
individual values - there's one called ADS_UF_LOCKOUT = 0X0010
I'd highly recommend the "Quick List of C# Code Samples" in the
http://msdn.microsoft.com/library/en-us/sds/sds/quick_list_for_c__code_examples.asp
Post by Tony TortoraPost by Marc Scheuner [MVP ADSI]It shows nicely how to do a lot of common things from C#, using S.DS.
As for unlocking - as far as I remember, only resetting the flag in
userAccountControl didn't suffice - you also needed to reset the
"lockoutTime" flag to a value of 0 (if memory serves me correctly).
Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch