Detect if your process is running in a Remote Desktop Services client session

Published

You could attempt to follow Microsoft's confusing guidance on this, use the Windows.System.RemoteDesktop.InteractiveSession.IsRemote WinRT API (Windows 10), or just call the WinStationIsCurrentSessionRemoteable Terminal Server API directly (Windows 8+).

Example declaration in C#:

[DllImport("winsta.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool WinStationIsCurrentSessionRemoteable(
[MarshalAs(UnmanagedType.Bool)] out bool isRemoteable);