我必须在 C# 中以编程方式锁定 Active Directory 中的用户帐户。
不幸的是,它不能通过 userAccountControl 属性工作。每次我将 userAccountControl 设置为 528(=带锁定标志的普通帐户)时,Active Directory 不会接受该值并将其重置为 512(=普通帐户),恕不另行通知。
现在我尝试通过提供不正确的凭据来锁定帐户(见下文),但这也不起作用。
int retries = 0;
while (!adsUser.IsAccountLocked && retries < MAX_LOCK_RETRIES)
{
retries++;
try
{
new DirectoryEntry(userPath, logonName, incorrectPassword).RefreshCache();
}
catch (Exception)
{
/* ... */
}
adsUser.GetInfo();
}
有什么想法吗?
最佳答案
确保您用于禁用帐户的帐户具有足够的权限来禁用帐户。参见 this example来自微软。
关于c# - 以编程方式锁定 Active Directory 帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/178730/