How do I tell if my application is running in an RDP session

后端 未结 4 786
旧时难觅i
旧时难觅i 2020-12-30 02:09

I have a .net winforms app which has a few animation effects, fade ins and scroll animations etc. These work fine however if I\'m in a Remote Desktop Protocol session the a

4条回答
  •  青春惊慌失措
    2020-12-30 02:42

    Use the GetSystemMetrics() function in the user32.dll. Use PInvoke to call it. The following is sample code provided by the first link. The second link tells you how to invoke it in .NET.

     BOOL IsRemoteSession(void){
          return GetSystemMetrics( SM_REMOTESESSION );
       }
    

    Complete code:

    [DllImport("User32.dll")]
    static extern Boolean IsRemoteSession()
    {
     return GetSystemMetrics ( SM_REMOTESESSION);
    }
    

    There's also the SystemInformation.TerminalServerSession Property, which determines whether or not the client is connected to a Terminal Server session. The code provided by MSDN is extensive, so I won't duplicate it here.

提交回复
热议问题