using System.DirectoryServices; // <-- Add a .NET reference to this namespace
string ExtLDAPQuery = "LDAP://my.ADInstance.Com/OU=OrgUnit,DC=My,DC=ADInstanc,DC=com";
string ExtLDAPUser = "MyUserID@my.ADInstance.Com";
string ExtLDAPPW = "MySuperSecurePassword";
string attrib = "msds-user-account-control-computed";
string temp = string.Empty;
// 0X0010 = 16 decimal
constint UF_LOCKOUT = 0x0010;
DirectoryEntry DE = new DirectoryEntry(ExtLDAPQuery, ExtLDAPUser, ExtLDAPPW, AuthenticationTypes.Secure);
DirectorySearcher DS = new DirectorySearcher(DE);
DE.Filter = "(&(objectcategory=person)(samaccountname=UsertoFind))";
SearchResult SR = DS.FindOne();
if (SR != null)
{
DirectoryEntry myDE = SR.GetDirectoryEntry();
//
// Iterate through the usual properties
//
foreach(string attrName in myDE.Properties.PropertyNames)
{
temp = myDE.Properties[attrName].Value.ToString();
//
// Do useful things with each attribute
//
}
//
// Now we can get the msds-user-account-control-computed attribute
// Note: If we attempt to do this prior to iterating through the usual
// list of properties, you'll get null for each property name
//
myDE.RefreshCache(newstring[]{attrib});
int flags =
(int)user.Properties[attrib].Value;
if(((flags & UF_LOCKOUT) == UF_LOCKOUT))
{
// The user's account is locked out...
}
}