Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if a program is running on a Remote Desktop

Tags:

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.

like image 963
Kluge Avatar asked Oct 01 '08 21:10

Kluge


People also ask

How do I check my RDP activity?

To view this remote desktop activity log, go to the Event Viewer. Under Applications and Services Logs -> Microsoft -> Windows -> Terminal-Services-RemoteConnectionManager > Operational.

What runs with RDP?

Clients exist for most versions of Microsoft Windows (including Windows Mobile), Linux (for example Remmina), Unix, macOS, iOS, Android, and other operating systems. RDP servers are built into Windows operating systems; an RDP server for Unix and OS X also exists (for example xrdp).


2 Answers

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

like image 60
Franci Penov Avatar answered Sep 20 '22 08:09

Franci Penov


Here's the C# managed code i use:

/// <summary> /// Indicates if we're running in a remote desktop session. /// If we are, then you MUST disable animations and double buffering i.e. Pay your taxes! ///  /// </summary> /// <returns></returns> public static Boolean IsRemoteSession {     //This is just a friendly wrapper around the built-in way     get     {         return System.Windows.Forms.SystemInformation.TerminalServerSession;     } } 
like image 28
Ian Boyd Avatar answered Sep 22 '22 08:09

Ian Boyd