How to

find out whether program is running in a remote session

Published: 19. November 2011 | Updated: 19. November 2011
License: Microsoft Public License (MS-PL)
Categories: Windows » Win32, Windows
Tags: C# Win32 Windows Winforms WPF
Was this snippet helpful for you? YESYES / NONO

Snippet example shows how to find out whether the calling process is associated with a Terminal Services client session

In WPF

using System.Windows;
bool remoteSession = SystemParameters.IsRemoteSession;

In Winforms

using System.Windows.Forms;
bool remoteSession = SystemInformation.TerminalServerSession;

Using Win API

using System.Runtime.InteropServices;
using System.Security;
[SuppressUnmanagedCodeSecurity]
[SecurityCritical]
[DllImport("user32.dll")]
public static extern int GetSystemMetrics(int index);
bool remoteSession = GetSystemMetrics(4096);
Send us feedback about this snippet »



Related Snippets: