Fazer uma PerguntaFazer uma Pergunta
 

RespondidoRetrieving windows user accounts

  • sábado, 11 de fevereiro de 2006 17:55A. Heuts Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    I'm trying to retrieve a list of all windows users, but all I can manage is the current user. I want to be able to connect software accounts to the windows accounts for automated login. How can I get a list of all windows users?

Respostas

  • quinta-feira, 23 de março de 2006 4:31James KovacsMVPMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    You can use the System.DirectoryServices.DirectoryEntry class to retrieve information on local users, groups, and services:

                using(DirectoryEntry root = new DirectoryEntry("WinNT://EDDINGS")) {
                    foreach(DirectoryEntry child in root.Children) {
                        if(child.SchemaClassName == "User") {
                            Console.WriteLine(child.Name);
                        }
                    }
                }

    SchemaClassName can also be Group or Service.

Todas as Respostas

  • domingo, 12 de fevereiro de 2006 4:40James KovacsMVPMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    What do you mean by "all Windows users"? All Windows Users currently logged onto a workstation? All local Windows user accounts? All Windows users in a domain? I would start looking at System.DirectoryServices to see if that can return the types of users you're looking for. A good article on this namespace is:
     
  • domingo, 12 de fevereiro de 2006 13:11A. Heuts Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    I meant all local windows user accounts.
  • quinta-feira, 2 de março de 2006 6:45Bappi Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    use

    System.DirectoryServices.DirectorySearcher object to find all the User Account in your local system

  • quinta-feira, 23 de março de 2006 4:31James KovacsMVPMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    You can use the System.DirectoryServices.DirectoryEntry class to retrieve information on local users, groups, and services:

                using(DirectoryEntry root = new DirectoryEntry("WinNT://EDDINGS")) {
                    foreach(DirectoryEntry child in root.Children) {
                        if(child.SchemaClassName == "User") {
                            Console.WriteLine(child.Name);
                        }
                    }
                }

    SchemaClassName can also be Group or Service.
  • quinta-feira, 23 de março de 2006 4:32James KovacsMVPMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Unfortunately System.DirectoryServices.DirectorySearcher doesn't work against the local security authority because it's not searchable. Use System.DirectoryServices.DirectoryEntry instead. (See code sample above.)