以编程方式检测 Windows Server 2008 上的控制台(管理)会话?
我的应用程序在 Windows Server 2008 下作为服务运行。我正在寻找一种方法来检测活动控制台会话。这可以是控制台,也可以是作为管理会话(“mstsc /admin”)启动的 RDP 会话。
控制台会话称为“Console”,但我对 RDP 会话感到困惑。 在 Windows 2003 下,这很容易,因为控制台会话始终以 id 0 运行。自 Vista 以来,这种情况发生了变化,因此我正在寻找另一种方法来找出答案。
我已经检查了 WTSxxx Win32 API,但没有找到我要找的东西。
有人可以帮忙吗?
My application is running as service under Windows Server 2008. I'm looking for a way to detect an active console session. This can either be the console or a RDP session started as administrative session ("mstsc /admin").
The console session is called "Console" but I'm lost with RDP sessions.
Under Windows 2003 it was easy because a console session was always running with id 0. This changed since Vista so I'm looking for another way to find out.
I've already checked the WTSxxx Win32 API but have not found what I'm looking for.
Can anybody help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您要查找当前附加到物理控制台的会话 ID,则 API 为 WTSGetActiveConsoleSessionId
If you're looking for the id of the session that is currently attached to the physical console, the API is WTSGetActiveConsoleSessionId
一种选择是让您的服务
CanHandleSessionChangeEvent
设置为 true,然后实施OnSessionChange(SessionChangeDescription changeDescription)
然后,如果ChangeDescription.Reason == SessionChangeReason.ConsoleConnect
您已经有人连接到控制台。One option is have your service
CanHandleSessionChangeEvent
set to true then implementOnSessionChange(SessionChangeDescription changeDescription)
Then ifChangeDescription.Reason == SessionChangeReason.ConsoleConnect
you have had someone connect to the console.