Lock/unlockAccount-Active Directory
Written by: Rickie Lee (http://www.cnblogs.com/rickie)
Determine whether the account is locked or not based on the isaccountlocked attribute. Because LDAP provider does not support the isaccountlocked attribute, winnt provider is used here: (Note that the provider identifier is case sensitive)
1.ObtainIsaccountlockedAttribute to determine whether or notLock/unlock
String struser = @ "winnt: // mydomain/" + domainuserid;
Directoryentry de = new directoryentry (struser );
Object objusr = de. nativeobject;
Type T = objusr. GetType ();
Bool boollocked = (bool) T. invokemember ("isaccountlocked", bindingflags. getproperty, null, objusr, null );
Boollocked = true indicates that the account is locked.
= False indicates that the account is unlocked.
2. Lock/unlock account
// Unlock an account
T. invokemember ("isaccountlocked", bindingflags. setproperty, null, objusr, new object [] {"false "});
// Lock an account
T. invokemember ("isaccountlocked", bindingflags. setproperty, null, objusr, new object [] {"true "});
De. commitchanges ();
References:
1. Rickie, update the gadgets for Active Directory/exchange Address Book, http://www.cnblogs.com/rickie/archive/2005/06/29/183043.html
2. Craig Aroa, adhelper-An Active Directory class,
Http://www.c-sharpcorner.com/Code/2002/Sept/ADClass.asp
3. Rickie, User Authentication Based on Active Directory, http://www.cnblogs.com/rickie/archive/2005/06/30/183700.html
4. Rickie, getting user information from Active Directory, http://www.cnblogs.com/rickie/archive/2005/07/01/184289.html
5. Rickie, updates user information in Active Directory, http://www.cnblogs.com/rickie/archive/2005/07/02/184927.html