当有多个用户同时登录时,如何列出当前登录的用户?
使用 WMI(无论实际的编程语言是什么),可以使用诸如 Select UserName from Win32_ComputerSystem
之类的查询来获取当前登录的用户。一切都很好。
但是,如果涉及多个用户会话和/或终端服务怎么办?是否可以列出给定系统上当前登录的所有用户?如何?
如果 WMI 不是此处的最佳选择,和/或如果有其他可用工具,请随时提供建议。我主要对 .NET/C# 感兴趣。
Using WMI (regardless of the actual programming language), it's possible to get the currently logged on user using a query such as Select UserName from Win32_ComputerSystem
. All nice and good.
But what if multiple user sessions and/or Terminal Services are involved? Is it possible to list all the currently logged on users on a given system? How?
If WMI is not the best option here, and/or if there are other available tools, feel free to advice. I'm mainly interested in .NET/C#.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个答案已经存在于网络上。你尝试过谷歌吗?我做了并发现(所有WMI相关) -
StackOverflow问题(这使得您的问题重复)
MSDN 博客条目 - 值得尝试
网络搜索结果
我强烈建议首先使用搜索引擎 - stackoverflow/web - 如果您仍然找不到答案,继续发布您的问题!
This answer already exists on net. Did you try Google? I did and found (all WMI related) -
StackOverflow question (this makes your question a duplicate)
MSDN blog entry - worth trying
Web search result
I strongly recommend using a search engine first - stackoverflow/web - and if you still can't find answers, go ahead and post your question!
您想要的是 WTSEnumerateSessions,但这将涉及 ap/invoke 调用。如果您想要一个不错的 C# 包装器库,我推荐 cassia。至于纯粹的WMI解决方案我不知道。
找到了 MSDN发布一些与您想要的类似的 WMI 调用。
What you want is WTSEnumerateSessions, however this will involve a p/invoke call. If you want a nice c# wrapper library I recommend cassia. As for a purely WMI solution I do not know.
Found a MSDN post about some WMI calls that are similar to what you want.