zoukankan      html  css  js  c++  java
  • AD

        ArrayList userlist=GetUsersArrayList(GetDirectoryEntryOfGroup("yyb"));

           

            for (int i = 0; i < userlist.Count; i++)
            {
                Response.Write(userlist[i].ToString());
            }

        }

        public static DirectoryEntry GetDirectoryObject()
        {
            string ADUser = "administrator";
            string ADPassword = "888888";
            string ADPath = "http://www.cnblogs.com/IsNull/admin/ldap://Test.com/";
            DirectoryEntry entry = new DirectoryEntry(ADPath, ADUser, ADPassword, AuthenticationTypes.Secure);
            return entry;
        }
        public static DirectoryEntry GetDirectoryEntryOfGroup(string groupName)
        {
            DirectoryEntry de = GetDirectoryObject();
            DirectorySearcher deSearch = new DirectorySearcher(de);
            deSearch.Filter = "(&(objectClass=group)(cn=" + groupName + "))";
            deSearch.SearchScope = SearchScope.Subtree;

            try
            {
                SearchResult result = deSearch.FindOne();
                de = new DirectoryEntry(result.Path);
                return de;
            }
            catch
            {
                return null;
            }
        }

        static ArrayList GetUsersArrayList(DirectoryEntry directoryEntry)
        {

            ArrayList arrUsers = new ArrayList();
            try
            {
                //Members
                foreach (object member in (IEnumerable)directoryEntry.Invoke("Members"))
                {
                    DirectoryEntry dirmem = new DirectoryEntry(member);
                    arrUsers.Add(dirmem.Name);
                   
                   
                }
                return arrUsers;
            }
            catch { return arrUsers; }
        }

  • 相关阅读:
    linux shell编程学习笔记(二) --- grep命令
    linux shell编程学习笔记(一)---通配符,元字符
    正则表达式
    leetcode problem 37 -- Sudoku Solver
    leetcode problem 33 -- Search in Rotated Sorted Array
    linux 终端快捷键
    linux中的sticky bit
    集中不等式
    Python os模块实例之遍历目录及子目录指定扩展名的文件
    Python模块之ConfigParser
  • 原文地址:https://www.cnblogs.com/IsNull/p/1763867.html
Copyright © 2011-2022 走看看