private bool IsAccountLocked( DirectoryEntry user ) { //if they have a lockoutTime if (user.Properties.Contains("lockoutTime")) { long fileTicks = LongFromLargeInteger(user.Properties["lockoutTime"].Value); //check to see if it's not already unlocked if (fileTicks != 0) { //now check to see if it was automatically unlocked DateTime lockoutTime = DateTime.FromFileTime(fileTicks); DirectoryEntry parent = user.Parent; while (parent.SchemaClassName != "domainDNS") parent = parent.Parent; long durationTicks = LongFromLargeInteger(parent.Properties["lockoutDuration"].Value); return (DateTime.Now.CompareTo(lockoutTime.AddTicks(-durationTicks)) < 0); } } return false; } //decodes IADsLargeInteger objects into a FileTime format (long) private long LongFromLargeInteger( object largeInteger ) { System.Type type = largeInteger.GetType(); int highPart = (int)type.InvokeMember("HighPart",BindingFlags.GetProperty, null, largeInteger, null); int lowPart = (int)type.InvokeMember("LowPart",BindingFlags.GetProperty, null, largeInteger, null); return (long)highPart << 32 | (uint)lowPart; }
Comments [0] January 28, 2005 Trackback
This is the personal site of Ryan Dunn, co-author of the The .NET Developers Guide to Directory Services Programming.
Ryan currently works for Microsoft and is the Technical Evangelist for SQL Server Data Services (SSDS)
Buy the Book
Contact Ryan