Exemplo n.º 1
0
        public IList <string> GetUsers()
        {
            var result = new List <string>();
            // get correct SidUserType string for Find method
            var sUsers = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null)
                         .Translate(typeof(NTAccount)).ToString();
            var inex          = sUsers.TakeWhile(c => c != '\\').Count();
            var sidTypeSubstr = sUsers.Substring(++inex);

            var    localMachine = new DirectoryEntry("WinNT://" + Environment.MachineName);
            var    usrGroup     = localMachine.Children.Find(sidTypeSubstr, "group");
            object members      = usrGroup.Invoke("members", null);

            foreach (object groupMember in (IEnumerable)members)
            {
                DirectoryEntry member = new DirectoryEntry(groupMember);
                result.Add(member.Name);
            }
            return(result);
        }