[英]How to get a list of Windows sessions?
I am trying to find a way to get a list of Windows sessions? 我想找到一种方法来获取Windows会话列表? I need the same information as the one displayed in the Task Manager on the User tab.
我需要与用户选项卡上任务管理器中显示的信息相同的信息。 I need to know if the user is active or not and if s/he is logged on in the Remote Desktop session.
我需要知道用户是否处于活动状态以及他/她是否在远程桌面会话中登录。
Any idea on how to do that with C# / Windows XP Pro? 有关如何使用C#/ Windows XP Pro做到这一点的想法?
As a starting point you can get a list of users logged on by running the command 作为起点,您可以通过运行命令获取登录用户的列表
qwinsta
From the command prompt. 从命令提示符。
This will give output like 这将给出输出
C:\WINDOWS\system32>qwinsta
SESSIONNAME USERNAME ID STATE TYPE DEVICE
>console me 0 Active wdcon
rdp-tcp 65536 Listen rdpwd
and will list any remote sessions. 并列出任何远程会话。
Use LsaEnumerateLogonSessions via P/Invoke. 通过P / Invoke使用LsaEnumerateLogonSessions 。 You'll also need LsaFreeReturnBuffer to cleanup after enumerating.
枚举后你还需要LsaFreeReturnBuffer来清理。
I believe you'll need to use P/Invoke to retrieve this information. 我相信你需要使用P / Invoke来检索这些信息。
The relevant APIs are documented in this MSDN page . 相关API记录在此MSDN页面中 。
Another way is to use the Logonsessions utility from Sysinternals: 另一种方法是使用Sysinternals的Logonsessions实用程序:
http://technet.microsoft.com/en-us/sysinternals/bb896769.aspx http://technet.microsoft.com/en-us/sysinternals/bb896769.aspx
You do not need to use Pinvoke. 您不需要使用Pinvoke。 WMI does it, and well: "select Name, SessionId from Win32_Process" in the root\\cimv2 namespace.
WMI做得很好,并且:在root \\ cimv2名称空间中“从Win32_Process中选择名称,SessionId”。 And, it can be called from a remote machine.
而且,它可以从远程机器调用。 Simpler.
简单。 Add in a where clause in the select to fine tune what you get back.
在select中添加where子句以微调你得到的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.