[英]How do I get a list of local Windows users who are logged in?
I'm trying to write a faster user switching app for Windows. 我正在尝试为Windows编写更快的用户切换应用程序。 Win+L and selecting users is very cumbersome.
Win + L并且选择用户非常麻烦。 If I start Task Manager as administrator, it shows active users and I can select one and "Connect" (if I enter their password).
如果我以管理员身份启动任务管理器,它会显示活动用户,我可以选择一个和“连接”(如果我输入他们的密码)。
How do I get the list of all users (or all active users)? 如何获取所有用户(或所有活动用户)的列表?
I'm using C# (Visual Studio Express). 我正在使用C#(Visual Studio Express)。
If you'd rather not deal with the P/Invokes, you can use Cassia , which wraps the ugly for you: 如果你不想处理P / Invokes,你可以使用Cassia ,它为你包裹丑陋:
using Cassia;
foreach (ITerminalServicesSession session in new TerminalServicesManager().GetSessions())
{
if (!string.IsNullOrEmpty(session.UserName))
{
Console.WriteLine("Session {0} (User {1})", session.SessionId, session.UserName);
}
}
我会尝试WTSEnumerateSessions来获取所有可用的会话。
You can also use NetWkstaUserEnum to see all users currently logged in; 您还可以使用NetWkstaUserEnum查看当前登录的所有用户; it's not really necessarily better, but it's another option.
它并不一定更好,但它是另一种选择。 It has one advantage that it will work on older systems which don't support terminal services, but that's probably not an issue if you're using C#.
它有一个优点,它可以在不支持终端服务的旧系统上运行,但如果您使用C#,这可能不是问题。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.