Detecting remote desktop connection

前端 未结 9 1663
北恋
北恋 2020-11-30 19:51

Is there anyway, in a program, to detect if a program is being run from inside a remote desktop session or if the program is being run normal in .NET 2.0? What I\'m trying t

9条回答
  •  北海茫月
    2020-11-30 20:45

    If you don't want to add a reference to System.Windows.Forms.dll just for this (as suggested above), then you can also call the underlying system call directly via PInvoke, like this:

        int result = GetSystemMetrics(SystemMetric.SM_REMOTESESSION);
        bool isRemoteSession = (result != 0);
    

    The SystemMetric enumeration can be found at PInvoke.net - SystemMetric (but you can just use the value of 0x1000); while the signature for GetSystemMetrics at PInvoke.net - GetSystemMetrics.

    I tested this with RDP and VNC - works with the former (admin/console mode also), does not detect the latter.

提交回复
热议问题