开发者

Programmatically detecting console (administrative) session on Windows Server 2008?

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?


If you're looking for the id of the session that is currently attached to the physical console, the API is WTSGetActiveConsoleSessionId


One option is have your service CanHandleSessionChangeEvent set to true then implement OnSessionChange(SessionChangeDescription changeDescription) Then if ChangeDescription.Reason == SessionChangeReason.ConsoleConnect you have had someone connect to the console.

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.
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜