简体   繁体   English

如何获取已登录的本地Windows用户列表?

[英]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.

相关问题 如何获取列表本地Windows用户(仅Windows登录屏幕中显示的用户) - How can I get a list Local Windows Users (Only the Users that appear in the windows Logon Screen) 如何获得使用IdenityServer4登录的用户的列表? - How can I get a list of logged in users with IdenityServer4? 如何获取.NET Core中登录用户的列表 - How to get a list of logged in users in .NET Core 如何使用获取所有已登录用户的列表 - How to get list of all logged in users using 如何让当前用户登录Windows? - How do I get current user logged in to windows? 我如何获得用户(不是我的Facebook朋友)个人资料图片 - How do I get a users (who is not my facebook friend) profile pic 如何在 .NET 中检索已登录/已连接用户的列表? - How do you retrieve a list of logged-in/connected users in .NET? 如何获取当前登录(经过身份验证)到IIS6的用户列表 - how to get a list of users currenltly logged in(Authenticated) to IIS6 如何在Windows 8.1(winRT)中获取本地文件夹大小 - How do I get Local folder size in Windows 8.1 (winRT) 如何获取TFS 2013中所有用户的列表 - How do I get list of all users in TFS 2013
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM