我的应用程序在Windows Server 2008下作为服务运行。我正在寻找一种检测活动控制台会话的方法。这可以是控制台,也可以是作为管理会话启动的RDP会话(“mstsc / admin”)。
控制台会话称为“控制台”但我在RDP会话中丢失了。 在Windows 2003下,它很容易,因为控制台会话始终以id 0运行。自Vista发生变化以来,我正在寻找另一种方法来查找。
我已经检查过WTSxxx Win32 API,但还没找到我要找的东西。
有人可以帮忙吗?
答案 0 :(得分:0)
一个选项是将您的服务CanHandleSessionChangeEvent
设置为true然后实施OnSessionChange(SessionChangeDescription changeDescription)
然后如果ChangeDescription.Reason == SessionChangeReason.ConsoleConnect
您有人连接到控制台。
protected override void OnSessionChange(SessionChangeDescription changeDescription)
{
if(changeDescription.Reason == SessionChangeReason.ConsoleConnect)
{
//use changeDescription.SessionId to find if the logged in user
// to that session is an administrator.
}
}
答案 1 :(得分:0)
如果您要查找当前附加到物理控制台的会话ID,则API为WTSGetActiveConsoleSessionId