• Upgrade your Internet Experience
  • Sign in
  • Microsoft.com
  • United States (English)
    Brasil (Português)Česká republika (Čeština)Deutschland (Deutsch)España (Español)France (Français)Italia (Italiano)Россия (Русский)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語)香港特别行政區 (中文)
 
 
Visual C# Developer Center
 
 
Home
 
 
Library
 
 
Learn
 
 
Downloads
 
 
Support
 
 
Community
 
 
Forums
 
 
 
Visual C# Developer Center > Visual C# Forums > Visual C# Language > Retrieving windows user accounts
Ask a questionAsk a question
Search Forums:
  • Search Visual C# Language Forum Search Visual C# Language Forum
  • Search All Visual C# Forums Search All Visual C# Forums
  • Search All MSDN Forums Search All MSDN Forums
 

AnswerRetrieving windows user accounts

  • Saturday, February 11, 2006 5:55 PMA. Heuts Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    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?

    • ReplyReply
    • QuoteQuote
     

Answers

  • Thursday, March 23, 2006 4:31 AMJames KovacsMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Vote As Helpful
    0
    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.
    • ReplyReply
    • QuoteQuote
     

All Replies

  • Sunday, February 12, 2006 4:40 AMJames KovacsMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    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:
     
    http://msdn.microsoft.com/msdnmag/issues/05/12/DirectoryServices/default.aspx
    • ReplyReply
    • QuoteQuote
     
  • Sunday, February 12, 2006 1:11 PMA. Heuts Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    I meant all local windows user accounts.
    • ReplyReply
    • QuoteQuote
     
  • Thursday, March 02, 2006 6:45 AMBappi Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    use

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

    • ReplyReply
    • QuoteQuote
     
  • Thursday, March 23, 2006 4:32 AMJames KovacsMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    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.)
    • ReplyReply
    • QuoteQuote
     
Need Help with Forums? (FAQ)
 
© 2009 Microsoft Corporation. All rights reserved.
Terms of Use
|
Trademarks
|
Privacy Statement