确定 Java 应用程序是否正在通过 RDP 会话运行?
如何检测我的 Swing 应用程序是否正在从 Windows RDP 会话运行?
仅使用 Java 的解决方案是首选,但该应用程序保证可以在 Windows 上运行,所以我可以接受。
How can I detect if my Swing App is being run from a windows RDP session?
Java only solution preferred, but the app is guaranteed to be running on windows so I'm ok with shelling out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您必须调用本机 Windows 库才能实现此目的。尝试这样的操作:
consoleSessionId
的奇怪情况来自 WTSGetActiveConsoleSessionId,其中表示:I think you'll have to invoke the native Windows libraries to pull this off. Try something like this:
That strange-looking condition for
consoleSessionId
is from the documentation for WTSGetActiveConsoleSessionId, which says:上述答案可能有效,但似乎不必要地复杂。您可以简单地读取 Windows 'sessionname' 环境变量来检测 RDP 会话。对于正常的本地会话,此环境变量的值将为“Console”。对于 RDP 会话,它将包含短语“RDP”。只需检查一下就很容易了。
测试并确认在Windows7 64位下工作。我注意到这种技术的一个问题是,一旦 JVM 启动,从 System.getenv() 读取的环境变量值似乎不会改变。因此,如果 JVM 进程是由控制台会话启动,但随后由 RDP 会话访问,则进一步调用 System.getenv("sessionname") 仍会返回“Console”。
The above answers might work, but seem needlessly complicated. You can simply read the windows 'sessionname' environment variable to detect RDP sessions. The value of this environment variable will be 'Console' for a normal, local session. For an RDP session it will contain the phrase 'RDP'. It's easy enough just to check for that.
Tested and confirmed working under Windows7 64bit. One issue I have noticed with this technique is that it appears that environment variable values as read from System.getenv() do not change once the JVM has started. So if the JVM process was started by a console session, but then accessed by an RDP session, further calls to System.getenv("sessionname") still return 'Console.'
尝试使用 NativeCall ( http://johannburkard.de/software/nativecall/ )
您所需要的只是类路径中有 2 个 jar 加上 1 个 DLL。
快速测试:
Try with NativeCall ( http://johannburkard.de/software/nativecall/ )
All you need is 2 jars plus 1 DLL in your classpath.
A quick test :