I had to figure out how to write all currently constructed Windows Users to the screen and managed it with this little piece of C# code:
using System.Management;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SelectQuery query = new SelectQuery("Win32_UserAccount");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject envVar in searcher.Get())
{
Console.WriteLine("Username : {0}", envVar["Name"]);
}
Console.ReadLine();
}
}
}
Depending on the PC it might eat up a little more time sometimes.
6 comments ↓
Thanks for the code!
thank you very much,
but i have a problem, why when i change the name of ana account the running result is still the same, the result not update? if the account name = student and i change it to teacher the result stay as the first run (student) how can i solve this problem, please tell me
You are awesome! I’ve been trying to get netenumuser to work but this is 1000% easier 🙂 Many, many thanks to you.
Thanks, thanks for the code!
Wow!
Just two lines of code on how to list all Windows Users! I wrote a 20-line function that did the same… (and, not to mention – it wasn’t really accurate!) 🙂
Thanks!
Great article ! It works.
Thank you !
Leave a Comment