Beispiel #1
0
        //загрузка всех пользователей
        public static CustomUserList GetUsers(string Filter = "")
        {
            CustomUserList users = new CustomUserList();

            var directoryEntry = new DirectoryEntry();

            directoryEntry.AuthenticationType = AuthenticationTypes.ReadonlyServer;
            var dirSearcher = new DirectorySearcher(directoryEntry);

            try
            {
                dirSearcher.SearchScope = SearchScope.Subtree;
                dirSearcher.Filter      = Filter == "" ? Properties.Settings.Default.filter : Filter;

                var searchResults = dirSearcher.FindAll();
                foreach (SearchResult sr in searchResults)
                {
                    DirectoryEntry de     = sr.GetDirectoryEntry();
                    HasUserInfo    ifUser = new DeUser(de);

                    CustomUser user = new CustomUser(ifUser);

                    users.Add(user);
                }
            }
            finally
            {
                directoryEntry.Dispose();
                dirSearcher.Dispose();
            }
            return(users);
        }
Beispiel #2
0
        public static void RefreshUser(CustomUser UserForChange)
        {
            using (DirectorySearcher dsSearcher = new DirectorySearcher())
            {
                dsSearcher.Filter = InputLDAP.SearchFilter(UserForChange.SAMAccountName);
                SearchResult   result = dsSearcher.FindOne();
                DirectoryEntry de     = result.GetDirectoryEntry();

                HasUserInfo ifUser = new DeUser(de);

                CustomUser NewUser = new CustomUser(ifUser);

                UserForChange.Copy(NewUser);
            }
        }