如何从浏览器检测用户是否正在远程桌面会话中运行?

发布于 2024-09-13 09:52:52 字数 677 浏览 5 评论 0原文

如果用户正在远程桌面会话中运行,是否有方法检查浏览器内部(例如 JavaScript)?


如果用户在远程桌面(即终端服务)内运行浏览器,我想禁用网站上的动画。

如果这是一个本机应用程序,而不是一个网站,我可以使用以下命令执行此检查:

//Native code
isRemoteSession = GetSystemMetrics( SM_REMOTESESSION );

或者

//Managed Code:
isRemoteSession = System.Windows.Forms.SystemInformation.TerminalServerSession;

是否可以在浏览器内完成类似的检查?

注意:出于本次讨论的目的,假设我们讨论的浏览器是 Internet Explorer 8。


更新一:也许如何从 javascript 获取终端服务客户端计算机名称?

Is there a ways to check inside a browser (e.g. javascript) if the user is running inside a Remote Desktop session?


If the user is running their browser inside a Remote Desktop (i.e. Terminal Services), i want to disable animations on the web-site.

If this were a native application, as opposed to a web-site, i could perform this checking using:

//Native code
isRemoteSession = GetSystemMetrics( SM_REMOTESESSION );

or

//Managed Code:
isRemoteSession = System.Windows.Forms.SystemInformation.TerminalServerSession;

Is there a similar check that can be done inside the browser?

Note: Assume for the purposes of this discussion that the browser we're talking about is Internet Explorer 8.


Update One: Perhaps something in How can you get the terminal service client machine name from javascript?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

飘逸的'云 2024-09-20 09:52:52

我的解决方案是使用 CSS @media 查询 颜色媒体功能。根据实验,RDP 似乎每种颜色只有 5 位,而不是典型桌面的每种颜色完整的 8 位。

当然,这个解决方案并不完美,因为您会从那些没有使用 RDP、但碰巧拥有低颜色深度显示器的人那里得到很多误报。但是:

  • 如果您处于企业内部网等相对受控的环境中,您可能会更有信心“低颜色深度”=“RDP”。
  • 网页上许多需要针对 RDP 进行调整的视觉元素,正是由于颜色深度较低(渐变、淡出、动画等)而需要进行调整,因此它实际上是有意义的测试颜色深度而不是 RDP 本身。

这是一个在最新版本的 Firefox 和 Chrome 中适用于我的示例。请参阅下面的屏幕截图。

<!DOCTYPE html>
<html>
    <head>
        <title>Test RDP detection</title>
        <style type="text/css">
            @media all { li.color { display: none; } }
            @media all and (min-color: 1) { li.color.color-depth-1 { display: block; } }
            @media all and (min-color: 2) { li.color.color-depth-2 { display: block; } }
            @media all and (min-color: 3) { li.color.color-depth-3 { display: block; } }
            @media all and (min-color: 4) { li.color.color-depth-4 { display: block; } }
            @media all and (min-color: 5) { li.color.color-depth-5 { display: block; } }
            @media all and (min-color: 6) { li.color.color-depth-6 { display: block; } }
            @media all and (min-color: 7) { li.color.color-depth-7 { display: block; } }
            @media all and (min-color: 8) { li.color.color-depth-8 { display: block; } }

            /* 5 bits per color seems to be the max for RDP */
            @media all and (max-color: 5) {
                .not-rdp { display: none; }
            }
            @media all and (min-color: 6) {
                .rdp-only { display: none; }
            }
        </style>
    </head>
    <body>
        <p>This page uses CSS <tt>@media</tt> queries to detect whether you
            are viewing it over RDP—heuristically, by looking at the
            color depth of your display.</p>

        <ul>
            <li class="color color-depth-1">Your display is not monochrome!</li>
            <li class="color color-depth-2">Your display has at least 2 bits per color.</li>
            <li class="color color-depth-3">Your display has at least 3 bits per color.</li>
            <li class="color color-depth-4">Your display has at least 4 bits per color.</li>
            <li class="color color-depth-5">Your display has at least 5 bits per color.</li>
            <li class="color color-depth-6">Your display has at least 6 bits per color.</li>
            <li class="color color-depth-7">Your display has at least 7 bits per color.</li>
            <li class="color color-depth-8">Your display has at least 8 bits per color.</li>
        </ul>

        <p>You are <span class="not-rdp">not</span> using RDP.</p>
        <p class="rdp-only">This is only visible over RDP.</p>
    </body>
</html>

显示带有和不带有 RDP 的测试页面的屏幕截图

另一种方法是使用 javascript 来检查 screen.colorDepth 变量。

My solution is to use CSS @media queries for minimum and maximum values of the color media feature. Based on experiment, RDP only seems to have 5 bits per color, rather than the full 8 bits per color of your typical desktop.

This solution is, of course, not perfect, because you'll get lots of false positives from people who aren't on RDP, but just happen to have low color-depth displays. However:

  • If you are in a relatively controlled environment like a corporate intranet, you might feel more confident that "low color depth" = "RDP".
  • Many of the visual elements that need adjusting for RDP on a web-page, need adjusting precisely because of the low color depth (gradients, fade outs, animation, etc.), and so it actually makes sense to test for color depth rather than RDP per se.

Here is an example that works for me in recent version of Firefox and Chrome. See the screenshot below.

<!DOCTYPE html>
<html>
    <head>
        <title>Test RDP detection</title>
        <style type="text/css">
            @media all { li.color { display: none; } }
            @media all and (min-color: 1) { li.color.color-depth-1 { display: block; } }
            @media all and (min-color: 2) { li.color.color-depth-2 { display: block; } }
            @media all and (min-color: 3) { li.color.color-depth-3 { display: block; } }
            @media all and (min-color: 4) { li.color.color-depth-4 { display: block; } }
            @media all and (min-color: 5) { li.color.color-depth-5 { display: block; } }
            @media all and (min-color: 6) { li.color.color-depth-6 { display: block; } }
            @media all and (min-color: 7) { li.color.color-depth-7 { display: block; } }
            @media all and (min-color: 8) { li.color.color-depth-8 { display: block; } }

            /* 5 bits per color seems to be the max for RDP */
            @media all and (max-color: 5) {
                .not-rdp { display: none; }
            }
            @media all and (min-color: 6) {
                .rdp-only { display: none; }
            }
        </style>
    </head>
    <body>
        <p>This page uses CSS <tt>@media</tt> queries to detect whether you
            are viewing it over RDP—heuristically, by looking at the
            color depth of your display.</p>

        <ul>
            <li class="color color-depth-1">Your display is not monochrome!</li>
            <li class="color color-depth-2">Your display has at least 2 bits per color.</li>
            <li class="color color-depth-3">Your display has at least 3 bits per color.</li>
            <li class="color color-depth-4">Your display has at least 4 bits per color.</li>
            <li class="color color-depth-5">Your display has at least 5 bits per color.</li>
            <li class="color color-depth-6">Your display has at least 6 bits per color.</li>
            <li class="color color-depth-7">Your display has at least 7 bits per color.</li>
            <li class="color color-depth-8">Your display has at least 8 bits per color.</li>
        </ul>

        <p>You are <span class="not-rdp">not</span> using RDP.</p>
        <p class="rdp-only">This is only visible over RDP.</p>
    </body>
</html>

screenshot showing test page with and without RDP

Yet another approach along these lines is to use javascript to examine the value of the screen.colorDepth variable.

豆芽 2024-09-20 09:52:52

您可以使用以下媒体查询:

@media screen and (prefers-reduced-motion: reduce) { 。 。 。 此条件

也适用于非 RDP 会话,但由于您的目的是禁用所有动画,因此这种类型的查询可能正是您正在寻找的。

You can use the following media query:

@media screen and (prefers-reduced-motion: reduce) { . . . }

This condition can also hold for non-RDP sessions, but as your intention is to disable all animations, this type of query is probably exactly what you're looking for.

避讳 2024-09-20 09:52:52

您可以通过 ActiveX 或 BHO 公开检测代码(例如 将属性分配给窗口对象BHO) 如果您使用 IE。

否则,如果您使用 ActiveX 播放器播放动画,请检查播放器的文档以查看它是否在远程桌面下自动调整帧速率。

您始终可以提供网站的低带宽版本,并指示用户在视频播放效果不满意时选择该网站而不是常规网站。

有关编写终端服务感知图形应用程序的提示,请检查 图形效果考虑,以及一般绩效指南

You can probably expose the detection code via an ActiveX or BHO (e.g. assign a property to the window object in BHO) if you use IE.

Otherwise if you are using an ActiveX player to play animation, check the player's documentation to see if it automatically adjust frame rate under remote desktop.

You can always offer a low bandwidth version of your web site and instruct the user choose the web site instead of the regular web site if the video playback is not satisfactory.

For tips in writing a terminal service-aware graphics app, check graphic effects consideration, and the general performance guidelines

草莓酥 2024-09-20 09:52:52

也许您可以读取 SESSIONNAME 环境变量?
对于控制台会话,它应该是 CONSOLE;对于 RDP 会话,它应该是 RDP-TCP,后跟一个数字。

Perhaps you can read the SESSIONNAME environment variable?
For a console session it should be CONSOLE and for an RDP session it should be RDP-TCP followed by a number.

深海不蓝 2024-09-20 09:52:52

我假设您正在谈论特定的公司终端服务器,而不是任何终端服务器。您无法向 TS 的特定 IP 地址提供动画。

I'm assuming you are talking about a specific company terminal server, not any terminal server. You could not serve animations to the specific IP address of the TS.

眼泪淡了忧伤 2024-09-20 09:52:52

这不应该由您的应用程序完成或决定。在 RDP 客户端(如 MS RDC)上,用户可以选择禁用动画等。用户也可以在服务器端(终端服务器或 RDP 主机)禁用这些

This should not be done or decided by your application. On RDP client (like MS RDC), user can choose to disable animations etc. User can also disable these on server side (Terminal server or RDP host)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文