Thanks Joe for the reply, to answer your question, Yes, UserA is a valid user, as I mentioned earlier, it is working many months until the admin unlock the id.
I am using user.Properties["userAccountControl"][0] to get the expiration based on below logic (I got it from Chapter 10 of the book)
public DateTime GetExpiration(DirectoryEntry user)
{
int flags =
(int)user.Properties["userAccountControl"][0];
//check to see if passwords expire
if (Convert.ToBoolean(flags & UF_DONT_EXPIRE_PASSWD))
{
//the user's password will never expire
return DateTime.MaxValue;
As I mentioned earlier, I am using UserB to get information of UserA. The strange thing is, if I use UserA account to get UserA info, I have no problem.
Here is how I use it:
DirectoryEntry root = new DirectoryEntry("LDAP://dc=ourdomain,dc=com", "UserB", "myPassword", AuthenticationTypes.Secure);
//point this to a user in the directory
DirectoryEntry user = null;
DirectorySearcher search = new DirectorySearcher(root);
search.Filter = "(sAMAccountName=" + "UserA" + ")";
Thanks Again.