Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何知道我的应用程序是否由远程桌面控制?_C#_Remote Desktop - Fatal编程技术网

C# 如何知道我的应用程序是否由远程桌面控制?

C# 如何知道我的应用程序是否由远程桌面控制?,c#,remote-desktop,C#,Remote Desktop,事件描述 当当前登录的用户发生更改时发生 该属性有一个属性,告诉您事件的原因 如果远程桌面连接或断开连接,则引发此事件 启动远程桌面时:Reason==SessionSwitchReason.RemoteConnect 远程桌面关闭时:原因==会话开关原因.RemoteDisconnect 如果在没有远程桌面的情况下启动程序,则属性IsRemoteSession为false。如果启动远程桌面,则会引发该事件,但该属性仍为false 但是,如果我用remote descktop启动程序,Is

事件描述

当当前登录的用户发生更改时发生

该属性有一个属性,告诉您事件的原因

如果远程桌面连接或断开连接,则引发此事件

  • 启动远程桌面时:Reason==SessionSwitchReason.RemoteConnect
  • 远程桌面关闭时:原因==会话开关原因.RemoteDisconnect

如果在没有远程桌面的情况下启动程序,则属性IsRemoteSession为false。如果启动远程桌面,则会引发该事件,但该属性仍为false

但是,如果我用remote descktop启动程序,IsRemoteSession为true。如果关闭远程桌面,则会引发该事件,但该属性仍为true

正如建议的那样,我还尝试了GetSystemMetrics,但也没有给出正确的值,这是可以预期的,因为SystemParameters使用GetSystemMetrics来获取值

class ViewModel
{
    public ViewModel()
    {
        SystemEvents.SessionSwitch += SessionSwitched;
        IsRemoteSession = SystemParameters.IsRemoteSession;

        Logger.LogTrace("ViewModel constructed. Remote Session {0}", this.IsRemoteSession);
    }

    public bool IsRemoteSession {get; set;}

    private void SessionSwitched(object sender, SessionSwitchEventArgs e)
    {
        this.IsRemoteSession = SystemParameters.IsRemoteSession;
        Logger.LogTrace("Session Switch. Reason: {0}; Remote Session {1}"
                         e.Reason, this.IsRemoteSession);
}