Retrieving windows user accounts<font size=2><span style="font-family:verdana,geneva,arial,sans-serif"></span></font> <p><font size=2><span style="font-family:verdana,geneva,arial,sans-serif">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?</span></font><br> </p>© 2009 Microsoft Corporation. All rights reserved.Thu, 19 Jun 2008 00:15:52 Zb46eb388-6f80-4524-9492-56c72fbae350http://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/b46eb388-6f80-4524-9492-56c72fbae350#b46eb388-6f80-4524-9492-56c72fbae350http://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/b46eb388-6f80-4524-9492-56c72fbae350#b46eb388-6f80-4524-9492-56c72fbae350A. Heutshttp://social.msdn.microsoft.com/Profile/en-US/?user=A.%20HeutsRetrieving windows user accounts<font size=2><span style="font-family:verdana,geneva,arial,sans-serif"></span></font> <p><font size=2><span style="font-family:verdana,geneva,arial,sans-serif">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?</span></font><br> </p>Sat, 11 Feb 2006 17:55:44 Z2006-03-23T04:31:30Zhttp://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/b46eb388-6f80-4524-9492-56c72fbae350#bc014372-7077-4579-9b80-3521a61c9681http://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/b46eb388-6f80-4524-9492-56c72fbae350#bc014372-7077-4579-9b80-3521a61c9681James Kovacshttp://social.msdn.microsoft.com/Profile/en-US/?user=James%20KovacsRetrieving windows user accounts<div>What do you mean by &quot;all Windows users&quot;? 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:</div> <div> </div> <div><a title="http://msdn.microsoft.com/msdnmag/issues/05/12/DirectoryServices/default.aspx" href="http://msdn.microsoft.com/msdnmag/issues/05/12/DirectoryServices/default.aspx">http://msdn.microsoft.com/msdnmag/issues/05/12/DirectoryServices/default.aspx</a></div>Sun, 12 Feb 2006 04:40:48 Z2006-02-12T04:40:48Zhttp://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/b46eb388-6f80-4524-9492-56c72fbae350#b54492d1-bda8-44b3-b756-212a9063ab6ahttp://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/b46eb388-6f80-4524-9492-56c72fbae350#b54492d1-bda8-44b3-b756-212a9063ab6aA. Heutshttp://social.msdn.microsoft.com/Profile/en-US/?user=A.%20HeutsRetrieving windows user accounts<font size=2><span style="font-family:geneva,arial,sans-serif">I meant all local windows user accounts.</span></font><br>Sun, 12 Feb 2006 13:11:12 Z2006-02-12T13:11:12Zhttp://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/b46eb388-6f80-4524-9492-56c72fbae350#5f008488-b60f-4ae1-bc33-8b96f674fa09http://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/b46eb388-6f80-4524-9492-56c72fbae350#5f008488-b60f-4ae1-bc33-8b96f674fa09Bappihttp://social.msdn.microsoft.com/Profile/en-US/?user=BappiRetrieving windows user accountsuse <font size=2> <p>System.DirectoryServices.</font><font color="#008080" size=2>DirectorySearcher object to find all the User Account in your local system</p></font>Thu, 02 Mar 2006 06:45:13 Z2006-03-02T06:45:13Zhttp://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/b46eb388-6f80-4524-9492-56c72fbae350#414f97dc-51b6-4a5f-ab97-69bd90a20fa0http://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/b46eb388-6f80-4524-9492-56c72fbae350#414f97dc-51b6-4a5f-ab97-69bd90a20fa0James Kovacshttp://social.msdn.microsoft.com/Profile/en-US/?user=James%20KovacsRetrieving windows user accountsYou can use the System.DirectoryServices.DirectoryEntry class to retrieve information on local users, groups, and services:<br><br>            using(DirectoryEntry root = new DirectoryEntry(&quot;WinNT://EDDINGS&quot;)) {<br>                foreach(DirectoryEntry child in root.Children) {<br>                    if(child.SchemaClassName == &quot;User&quot;) {<br>                        Console.WriteLine(child.Name);<br>                    }<br>                }<br>            }<br><br>SchemaClassName can also be Group or Service.<br>Thu, 23 Mar 2006 04:31:24 Z2006-03-23T04:31:30Zhttp://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/b46eb388-6f80-4524-9492-56c72fbae350#462f4bed-2706-4a32-9f4f-6b762972eb41http://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/b46eb388-6f80-4524-9492-56c72fbae350#462f4bed-2706-4a32-9f4f-6b762972eb41James Kovacshttp://social.msdn.microsoft.com/Profile/en-US/?user=James%20KovacsRetrieving windows user accountsUnfortunately 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.)<br>Thu, 23 Mar 2006 04:32:35 Z2006-03-23T04:32:35Z