简体   繁体   中英

How to unlock User accounts in AD using lockoutTime

I want to unlock user account in AD by setting the lockoutTime attribute to zero. The problem is that the value of the property is a System_ComObject. How do I set the value of the attribute to zero? I have used the following code to get the value of lockOut .

DirectoryEntry user = DirectoryEntry(DistinguishedName);

//user.Properties["lockoutTime"].Value is a System_Com object

long fileTicks = LongFromLargeInteger(user.Properties["lockoutTime"].Value);

private long LongFromLargeInteger(object largeInteger)
{
    System.Type type = largeInteger.GetType();
    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;
}

All you need to do is this:

user.Properties["LockOutTime"].Value = 0;
user.CommitChanges();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM