锁定 Active Directory 帐户的首选方法是什么?
int val = (int)directoryentry.Properties["userAccountControl"].Value;
directoryentry.Properties["userAccountControl"].Value = val | 0x0010;
对比
directoryentry.InvokeSet("IsAccountLocked", true);
有没有更好的办法?
最佳答案
您使用的是 .NET 3.5(或者您可以升级到它)吗?
如果是这样,请查看新的 System.DirectoryServices.AccountManagement
命名空间及其提供的所有功能!优秀的介绍是MSDN article Managing Directory Security Principals in the .NET Framework 3.5 .
对于您的情况,您必须以某种方式获取 UserPrincipal
,例如
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "YOURDOMAIN");
UserPrincipal me = UserPrincipal.Current;
然后您可以访问大量非常易于使用的属性和方法 - 例如:
bool isLockedOut = me.IsAccountLockedOut();
您可以使用以下方式解锁锁定的帐户:
me.UnlockAccount();
MUCH 比普通的旧 System.DirectoryServices
东西更容易!
关于c# - Active Directory LDAP - 锁定用户帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2768382/