Detecting remote desktop connection

前端 未结 9 1668
北恋
北恋 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:27

    Just a note to say that using GetSystemMetrics(SystemMetric.SM_REMOTESESSION) on its own has stopped being reliable for Windows 8 / Server 2012 onwards if the session is using RemoteFX virtualisation of the GPU.

    The "official" method of detecting RDS is described by Microsoft here: Detecting the Remote Desktop Services environment (Last updated 31 May 18).

    It consists of using the SystemMetrics call and a registry check at

    HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\GlassSessionId
    

    The code samples in that article are C++ only, but given that it's just a registry lookup, I don't think folks will find it too tricksty to replicate in other languages.

    I'd like to hope that at least some of the .Net built in functions mentioned upthread are following this in full, but :

    • SystemParameters.IsRemoteSession is noted here as "Maps to SM_REMOTESESSION. See GetSystemMetrics", and

    • SystemParameters.IsRemotelyControlled is noted here as the same,

    so I'm not optimistic.

    I'll try to do some detailed checks shortly and post the results.

提交回复
热议问题