c# - 以编程方式锁定 Active Directory 帐户

标签 c# active-directory

我必须在 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/

相关文章:

c# - 用C#通过串口发送一个64字节的数据包

c# - 得墨忒耳法则困惑

c# - 使用 C# Async Await 进行负载测试

windows-7 - "Active Directory Users and Computers"Windows 7 的 MMC 管理单元?

JAVA - 使用 JNDI 或 Spring LDAP 从 AD 获取最大密码期限 (maxPwdAge)?

c# - 使用 OWIN 自托管 ASP.NET Web API 时,我应该如何存储每个请求数据

permissions - Sitecore Active Directory 权限和角色中的角色问题

java - Active Directory userPrincipleName 与用户登录名不同

asp.net - Active Directory帐户的Oauth 2 token

java - 将 Java byte[].class 转换为 C#