如何在LDAP C#中获取属性(帐户被禁用)

时间:2016-06-03 14:40:12

标签: c# ldap

如何获取财产帐户? 我有一个联系人列表,想知道一个工人是否活跃

this property - image

我的有关具有Active Directory的员工的获取者信息。我需要一个确定工人是否有效的属性。


 public List<string> SomeInformation()
    {
        List<string> lista = new List<string>();

        try
        {
            DirectoryEntry myLdapConnection = SearchRoot;
            DirectoryEntry gbvision = myLdapConnection.Children.Find("OU=WN");
            DirectorySearcher search = new DirectorySearcher(gbvision);

            search.Filter = "(&(objectClass=user))";



            // create an array of properties that we would like and  
            // add them to the search object  

            string[] requiredProperties = new string[] { "cn", "mail", "telephoneNumber", "title", "mobile", "department" };

            foreach (String property in requiredProperties)
                search.PropertiesToLoad.Add(property);


            foreach (SearchResult result in search.FindAll())
            {

                if (result != null)
                {
                    foreach (String property in requiredProperties)
                    {
                        foreach (Object myCollection in result.Properties[property])
                        {
                            Console.WriteLine(String.Format("{0,-20} : {1}", property, myCollection.ToString()));
                            lista.Add(property + myCollection);
                        }
                    }
                    lista.Add("END");


                }
                else
                {
                    Console.WriteLine("User not found!");
                }
            }
        }

        catch (Exception e)
        {
            Console.WriteLine("Exception caught:\n\n" + e.ToString());
        }
        return lista;

    }

2 个答案:

答案 0 :(得分:1)

您可以使用此LDAP过滤器查看帐户是否已停用:

vector<wstring>

所以要获得活跃用户:

(UserAccountControl:1.2.840.113556.1.4.803:=2)

答案 1 :(得分:0)

感谢您的回复,使用此过滤器后,我似乎没有用户列表。我找到了一个解决方案,它是:

var accountIsDisabled = Convert.ToBoolean(int.Parse(flag) & 0x0002);