如何检测remtote桌面会话已关闭 - C#? [英] How to detect that a remtote desktop session has been closed - C#?

查看:55
本文介绍了如何检测remtote桌面会话已关闭 - C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi


我正在使用C#开发一个Windows服务,它必须监视对运行它的计算机所做的远程桌面登录,并将状态发送到服务器。

我使用以下代码确定它是否是远程桌面会话

Hi
I am developing a Windows service in C# that has to monitor remote desktop logins that are made to the machine that it is running on and send the status to a server.
I was using the following piece of code to determine if it is a Remote Desktop Session or not

if (System.Windows.Forms.SystemInformation.TerminalServerSession == true)
       {
           isRemoteSession = true;
       }
       else
       {
           isRemoteSession = false;
       }





我意识到,一旦我关闭我的特定属性TerminalServerSession就不会设置为false远程桌面窗口。只有在我正常登录该特定计算机时才会将其设置为false。



我的要求是在远程桌面关闭后立即检测状态。

有谁能帮帮我吗?



提前致谢!



What I realized is that this particular property "TerminalServerSession" is NOT set to false as soon as I CLOSE my remote desktop window. It is being set to false only when I do a normal login to that particular machine.

My requirement is to detect the status as soon as the Remote Desktop has been closed.
Can anyone please help me out here?

Thanks in advance!

推荐答案

你有从缓冲区读取的所有内容吗?如果要读取的缓冲区中有信息,那么在清除缓冲区之前它可能不会恢复断开状态。



希望这会给你一个想法。
have you read everything from the buffer? If there is information in the buffer to be read, then it might not pick up the disconnected state until the buffer is cleared.

Hope this will give you an idea.






你应该听:

Hi,

you should listen to:
SystemEvents.SessionSwitch += new SessionSwitchEventHandle SystemEvents_SessionSwitch);





活动中Args有一个SessionSwitchReason(e.Reason):SessionLock,SessionUnlock等等已经

RemoteDisconnect和RemoteConnect



In the Event Args there is a SessionSwitchReason(e.Reason) : SessionLock, SessionUnlock etc. and there is already
RemoteDisconnect and RemoteConnect

void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
    if (e.Reason == SessionSwitchReason.SessionLock || e.Reason == SessionSwitchReason.RemoteDisconnect || e.Reason == SessionSwitchReason.SessionLogoff)
    {

    }
    else if (e.Reason == SessionSwitchReason.SessionUnlock || e.Reason == SessionSwitchReason.RemoteConnect || e.Reason == SessionSwitchReason.SessionLogon)
    {

    }
}





希望有帮助



Hope that helps


不是答案,与问题无关。



写作(见问题)

Not an Answer, not related to the Question.

Writing (see the Question)
if (System.Windows.Forms.SystemInformation.TerminalServerSession == true)
       {
           isRemoteSession = true;
       }
       else
       {
           isRemoteSession = false;
       }



而不是


instead of

isRemoteSession = System.Windows.Forms.SystemInformation.TerminalServerSession;



让我没有多大希望。



此外, System.Windows.Forms .SystemInformation.TerminalServerSession 属性指示应用程序(调用进程)作为远程会话的一部分在服务器计算机上运行。始终 true false ,无法检测连接或断开连接。当然,对于您的Windows服务,它将是 false 。这个检查根本无法帮助你。



对不起, Lydiae 。试想一下。



-SA


leaves me without much hope.

Besides, System.Windows.Forms.SystemInformation.TerminalServerSession property indicate that the application (calling process) is run on a server computer as a part of remote session. It is always either true of false, cannot detect connection or disconnection. And certainly it will be false for your Windows Service. This check cannot help you at all.

Sorry, Lydiae. Just think about it.

—SA


这篇关于如何检测remtote桌面会话已关闭 - C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆