public bool RemoveUser(string userName) { try { UserManager.DeleteUser(userName); return(true); } catch (Exception ex) { return(false); } }
protected void DoSychronizationCleanRTX(DirectoryEntry root_entry) { string all_users = RootObj.QueryUsersByState("online") + RootObj.QueryUsersByState("offline") + RootObj.QueryUsersByState("away"); foreach (string user in all_users.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) { DirectorySearcher search = new DirectorySearcher(root_entry); search.Filter = "(&(objectclass=user)(samaccountname=" + user.Substring(0, user.IndexOf('@')) + "))"; search.PropertiesToLoad.Add("cn"); SearchResult result = search.FindOne(); if (result == null) { UserManagerObj.DeleteUser(user); } } }