获取在Windows本地计算机的用户名列表 [英] Get list of local computer usernames in Windows

查看:368
本文介绍了获取在Windows本地计算机的用户名列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用C#获取本地计算机上的用户名在窗口的列表?


解决方案

 使用System.Management;SelectQuery查询=新SelectQuery(Win32_UserAccount);
ManagementObjectSearcher搜索=新ManagementObjectSearcher(查询);
的foreach(的ManagementObject ENVVAR在searcher.Get())
{
     Console.WriteLine(用户名:{0},ENVVAR [名称]);
}

这code是一样的href=\"http://www.andreas-kraus.net/blog/how-to-list-all-windows-users/\">链接KeithS张贴。我用它在几年前没有问题,但已经忘记了它是从哪里来的,感谢基思。

How can I get a list of local computer usernames in windows using C#?

using System.Management;

SelectQuery query = new SelectQuery("Win32_UserAccount");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject envVar in searcher.Get())
{
     Console.WriteLine("Username : {0}", envVar["Name"]);
}

This code is the same as the link KeithS posted. I used it a couple years ago without issue but had forgotten where it came from, thanks Keith.

这篇关于获取在Windows本地计算机的用户名列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆