Determine if a program is running on a Remote Desktop

citrix, terminal-services, windows

Solution

GetSystemMetrics(SM_REMOTESESSION) (as described in http://msdn.microsoft.com/en-us/library/aa380798.aspx)

Problem

Is there a way my program can determine when it's running on a Remote Desktop (Terminal Services)? I'd like to enable an "inactivity timeout" on the program when it's running on a Remote Desktop session. Since users are notorious for leaving Remote Desktop sessions open, I want my program to terminate after a specified period of inactivity. But, I don't want the inactivity timeout enabled for non-RD users.

Original source