当有多个用户同时登录时,如何列出当前登录的用户?

发布于 2024-09-27 04:02:50 字数 259 浏览 0 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美人骨 2024-10-04 04:02:50

这个答案已经存在于网络上。你尝试过谷歌吗?我做了并发现(所有WMI相关) -

  1. StackOverflow问题(这使得您的问题重复)

  2. MSDN 博客条目 - 值得尝试

  3. 网络搜索结果

我强烈建议首先使用搜索引擎 - stackoverflow/web - 如果您仍然找不到答案,继续发布您的问题!

This answer already exists on net. Did you try Google? I did and found (all WMI related) -

  1. StackOverflow question (this makes your question a duplicate)

  2. MSDN blog entry - worth trying

  3. 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!

把梦留给海 2024-10-04 04:02:50

您想要的是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文