I have some code in a standard WPF program in which I want to know whether the computer on which my program runs is remote controlled.
For this I use SystemParameters.IsRemoteControlled as was suggested in this answer.
SystemParameters.IsRemoteControlled: true if the current session is remotely controlled; otherwise, false. This system metric is used in a Terminal Services environment. Maps to SM_REMOTECONTROL. See GetSystemMetrics.
private bool IsRemoteControlled => SystemParameter.IsRemoteControlled();
Alas, if I start my program while I use Remote Desktop or TeamViewer to control the program, the value is false, even if I run the program on a computer without a monitor.
Using GetSystemMetrics in a console program, doesn't help, I still get false.
static void Main(string[] args)
{
bool isRemoteControlled = GetIsRemoteControlled();
Console.WriteLine(isRemoteControlled);
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int GetSystemMetrics(SystemMetric smIndex);
private static bool GetTerminalServerSession()
{
const int SM_REMOTECONTROL = 0x2001;
int result = GetSystemMetrics(SM_REMOTECONTROL);
bool isRemoteSession = (result != 0);
return isRemoteSession;
}
So how do I know whether the computer is remote controlled, using remote desktop, and preferably using any remote control program. What event is associated with the value change?