Henry
2004-07-01 12:24:03 UTC
I have the following code,
string ldapPath = @"LDAP://DEV-DB1:50000/OU=Customers,O=MyDomain,C=us";
string userName = "CN=Admin,O=MyDomain,C=us";
string password = "Abcde1234";
string queryFilter =
string.Format("(&(&(objectClass=user)(objectCategory=person))(|(cn={0})))",
"ignhenry" );
string[] propertiesToLoad =
{
"cn", "distinguishedName", "isPasswordGenerated",
"lastBadPasswordCount", "name", "msDS-UserAccountDisabled",
"msDS-UserPasswordExpired", "objectGUID", "pwdLastSet",
"whenChanged", "whenCreated", "description", "givenName", "mail",
"middleName", "postalAddress", "postalCode", "title"
};
DirectoryEntry deContainer = null;
DirectorySearcher searcher = null;
DirectoryEntry deObject = null;
try
{
deContainer = new DirectoryEntry( ldapPath, userName, password,
AuthenticationTypes.ServerBind );
deContainer.RefreshCache();
searcher = new DirectorySearcher(deContainer);
searcher.Filter = queryFilter;
searcher.PropertiesToLoad.AddRange( propertiesToLoad );
searcher.SearchScope = SearchScope.Subtree;
SearchResult result = searcher.FindOne();
deObject = null;
if ( result != null )
deObject = result.GetDirectoryEntry();
bool userPasswordExpired = false;
if ( deObject.Properties.Contains("msDS-UserPasswordExpired") )
userPasswordExpired = (bool)
deObject.Properties["msDS-UserPasswordExpired"].Value;
}
catch (COMException ex)
{
string msg = ex.Message;
int errCode = ex.ErrorCode;
throw;
}
catch (Exception ex)
{
string msg = ex.Message;
throw;
}
finally
{
if ( deContainer != null ) { deContainer.Close(); deContainer.Dispose(); }
if ( deObject != null ) { deObject.Close(); deObject.Dispose(); }
if ( searcher != null ) { deContainer.Dispose(); }
}
The code gives me no error except I cannot get value for
"msDS-UserPasswordExpired" attribute even its value is actually exists. I
have checked that the user object has value for that attribute. Anyone can
see what am I doing wrong here?
Thanks
Henry
string ldapPath = @"LDAP://DEV-DB1:50000/OU=Customers,O=MyDomain,C=us";
string userName = "CN=Admin,O=MyDomain,C=us";
string password = "Abcde1234";
string queryFilter =
string.Format("(&(&(objectClass=user)(objectCategory=person))(|(cn={0})))",
"ignhenry" );
string[] propertiesToLoad =
{
"cn", "distinguishedName", "isPasswordGenerated",
"lastBadPasswordCount", "name", "msDS-UserAccountDisabled",
"msDS-UserPasswordExpired", "objectGUID", "pwdLastSet",
"whenChanged", "whenCreated", "description", "givenName", "mail",
"middleName", "postalAddress", "postalCode", "title"
};
DirectoryEntry deContainer = null;
DirectorySearcher searcher = null;
DirectoryEntry deObject = null;
try
{
deContainer = new DirectoryEntry( ldapPath, userName, password,
AuthenticationTypes.ServerBind );
deContainer.RefreshCache();
searcher = new DirectorySearcher(deContainer);
searcher.Filter = queryFilter;
searcher.PropertiesToLoad.AddRange( propertiesToLoad );
searcher.SearchScope = SearchScope.Subtree;
SearchResult result = searcher.FindOne();
deObject = null;
if ( result != null )
deObject = result.GetDirectoryEntry();
bool userPasswordExpired = false;
if ( deObject.Properties.Contains("msDS-UserPasswordExpired") )
userPasswordExpired = (bool)
deObject.Properties["msDS-UserPasswordExpired"].Value;
}
catch (COMException ex)
{
string msg = ex.Message;
int errCode = ex.ErrorCode;
throw;
}
catch (Exception ex)
{
string msg = ex.Message;
throw;
}
finally
{
if ( deContainer != null ) { deContainer.Close(); deContainer.Dispose(); }
if ( deObject != null ) { deObject.Close(); deObject.Dispose(); }
if ( searcher != null ) { deContainer.Dispose(); }
}
The code gives me no error except I cannot get value for
"msDS-UserPasswordExpired" attribute even its value is actually exists. I
have checked that the user object has value for that attribute. Anyone can
see what am I doing wrong here?
Thanks
Henry