SystemParameters.IsRemotelyControlled始终为false

问题描述

我在标准WPF程序中有一些代码,我想在其中了解运行我的程序的计算机是否是远程控制的。

为此,我按照SystemParameters.IsRemoteControlled的建议使用this answer

SystemParameters.IsRemoteControlled:如果当前会话是远程控制的,则为true;否则为false。 否则为假。 此系统指标用于终端服务环境。 映射到SM_REMOTECONTROL。请参阅GetSystemMetrics。

private bool IsRemoteControlled => SystemParameter.IsRemoteControlled();

A,如果我在使用远程桌面或TeamViewer来控制程序时启动程序,则即使我在没有监视器的计算机上运行该程序,该值也为false。

在控制台程序中使用GetSystemMetrics并没有帮助,我仍然会出错。

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;
}

那么我怎么知道计算机是否是使用远程桌面进行远程控制的,最好是使用任何远程控制程序进行的。值更改与哪个事件有关?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)