How to get all user account info in C# (windows VISTA/7).

Locked How to get all user account info in C# (windows VISTA/7).

  • Monday, February 22, 2010 1:50 PM
     
     
    Hey guys,

    is there a way to get the information (username, home directory, user group, ...) from every user account on a windows machine (VISTA / 7). I'm running the program as an Administrator so rights shouldn't be a problem.

    Ofcourse the passwords aren't needed.

    Thanks in advance!!!

All Replies

  • Monday, February 22, 2010 3:59 PM
     
     Answered
    Some info of the user:

                MessageBox.Show(Environment.UserDomainName.ToString());
                MessageBox.Show(Environment.UserName.ToString());

    Also review this link

    Si la respuesta te ha sido util Marcala como Respuesta o Votala.
    Mi Blog: Jtorrecilla
    Enlace a Faq de Winforms en Ingles Muy bueno
  • Tuesday, February 23, 2010 1:36 AM
     
     Answered Has Code

    Try this (add a reference to System.DirectoryServices.AccountManagement):

                PrincipalContext ctx = new PrincipalContext(ContextType.Machine,Environment.MachineName);
                UserPrincipal user = new UserPrincipal(ctx);
                user.Name = "*";
                PrincipalSearcher ps = new PrincipalSearcher();
                ps.QueryFilter = user;
                PrincipalSearchResult<Principal> result = ps.FindAll();
                foreach (Principal p in result)
                {
                    using (UserPrincipal up = (UserPrincipal)p)
                    {
                        MessageBox.Show(up.Name);
                    }
                }



    Compensating what I don't know yet, with what I do know now.

  • Wednesday, August 04, 2010 1:06 AM
     
      Has Code

    Try this (add a reference to e436f System.DirectoryServices.AccountManagement):

          PrincipalContext ctx = new PrincipalContext(ContextType.Machine,Environment.MachineName);      UserPrincipal user = new UserPrincipal(ctx);      user.Name = "*";      PrincipalSearcher ps = new PrincipalSearcher();      ps.QueryFilter = user;      PrincipalSearchResult<Principal> result = ps.FindAll();      foreach (Principal p in result)      {        using (UserPrincipal up = (UserPrincipal)p)        {          MessageBox.Show(up.Name);        }      }

     


    Compensating what I don't know yet, with what I do know now.

     


    Great! I solved the problem with your workaround. Thanks.
  • Saturday, April 14, 2012 4:20 AM