【问题标题】:How to read userAccountControl如何读取 userAccountControl
【发布时间】:2015-07-06 15:33:31
【问题描述】:

我需要知道一个帐户是否是:

  • 启用/禁用
  • 锁定/解锁
  • 密码过期/永不过期
  • 密码可以更改/不能更改
  • 需要密码/不需要密码

我可以从哪些 userAccountControl 值知道该帐户是上述帐户之一?

【问题讨论】:

    标签: active-directory ldap


    【解决方案1】:

    此字段是位掩码。您可以查看https://msdn.microsoft.com/en-us/library/aa772300(v=vs.85).aspx 以查看各个字段。

    【讨论】:

      【解决方案2】:

      userAccountControl 是 Active Directory 中包含这些位值的字段。您可以使用 LDAP 查询来使用在我之前在 Brian 的响应中找到的值来查找满足您希望在该字段上的任何标准的帐户。这是一个检查指定用户是否被禁用的示例。

      public bool checkDisabled(string domainFQDN, string alias)
      {
          bool disabled = false;
      
          try
          {
              using (DirectoryEntry domainDE = new DirectoryEntry("LDAP://" + domainFQDN, "domain\\cn", "password", AuthenticationTypes.Secure))
              {
                  using (DirectorySearcher searcher = new DirectorySearcher(domainDE))
                  {
                      searcher.Filter = String.Format("(&(objectClass=user)(cn={0})(userAccountControl:1.2.840.113556.1.4.803:=2))", alias);
                      disabled = (searcher.FindOne() != null);
                  }
              }
          }
          catch (Exception ex)
          {
              EventLog.WriteEntry("source name", MethodBase.GetCurrentMethod().DeclaringType + "." + MethodBase.GetCurrentMethod().Name + "\r\n\r\nUnable to get user's token groups for domain: " + domainFQDN + " user: " + alias + "\r\n\r\n" + ex.Message, EventLogEntryType.Error);
          }
      
          return disabled;
      } 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-22
        • 1970-01-01
        相关资源
        最近更新 更多