windows 如何从浏览器检测用户是否在远程桌面会话中运行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3417883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to detect, from browser, if user is running in Remote Desktop session?
提问by Ian Boyd
Is there a ways to check inside a browser (e.g. javascript) if the user is running inside a Remote Desktop session?
如果用户在远程桌面会话中运行,是否有办法检查浏览器(例如 javascript)内部?
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.
注意:为了本次讨论的目的,假设我们正在讨论的浏览器是 Internet Explorer 8。
Update One:Perhaps something in How can you get the terminal service client machine name from javascript?
更新一:也许在How can you get the terminal service client machine name from javascript?
回答by Maxy-B
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.
我的解决方案是对媒体功能的@media
最小值和最大值使用 CSS查询。根据实验,RDP 似乎每种颜色只有 5 位,而不是典型桌面的每种颜色全部 8 位。color
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:
当然,此解决方案并不完美,因为您会从未使用 RDP 但恰好具有低色深显示器的人那里得到很多误报。然而:
- 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 becauseof 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.
- 如果您处于企业内部网等相对受控的环境中,您可能会对“低色深”=“RDP”更有信心。
- 许多需要针对网页上的 RDP 进行调整的视觉元素,由于颜色深度较低(渐变、淡出、动画等)而需要进行精确调整,因此测试颜色深度而不是测试颜色深度实际上是有意义的RDP本身。
Here is an example that works for me in recent version of Firefox and Chrome. See the screenshot below.
这是一个在最新版本的 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>
Yet another approach along these lines is to use javascript to examine the value of the screen.colorDepth
variable.
另一种方法是使用 javascript 来检查screen.colorDepth
变量的值。
回答by u109919
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.
如果您使用 IE,您可能可以通过 ActiveX 或 BHO(例如,将属性分配给BHO中的 window 对象)公开检测代码。
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.
否则,如果您使用 ActiveX 播放器播放动画,请查看播放器的文档,看看它是否在远程桌面下自动调整帧速率。
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
回答by Remko
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.
也许您可以阅读 SESSIONNAME 环境变量?对于控制台会话,它应该是 CONSOLE,对于 RDP 会话,它应该是 RDP-TCP 后跟一个数字。
回答by Trevor Ian Peacock
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.
我假设您在谈论特定的公司终端服务器,而不是任何终端服务器。您无法向 TS 的特定 IP 地址提供动画。
回答by user186188
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)
这不应由您的应用程序完成或决定。在 RDP 客户端(如 MS RDC)上,用户可以选择禁用动画等。用户也可以在服务器端(终端服务器或 RDP 主机)禁用这些