Lock/Unlock Account - Active Directory

根据 IsAccountLocked 属性来判断 Account 是否 Lock/Unlock ,因为 LDAP provider 不支持 IsAccountLocked 属性,这里采用 WinNT Provider :(注意 Provider 提供程序标识符区分大小写)
 
1. 获取 IsAccountLocked 属性,判断是否 Lock/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 表示 account is locked.
           = False 表示 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, 更新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, 基于Active Directory的用户验证, http://www.cnblogs.com/rickie/archive/2005/06/30/183700.html
4. Rickie, Active Directory中获取用户信息, http://www.cnblogs.com/rickie/archive/2005/07/01/184289.html
5. Rickie, 更新 Active Directory 中用户信息 , http://www.cnblogs.com/rickie/archive/2005/07/02/184927.html

你可能感兴趣的:(职场,Lock,休闲,ad)