新 RDP 客户端的保持活动代码失败
对于我们的安全终端服务器项目,我们需要保持 RDP 会话打开,即防止远程计算机超时并锁定会话。 一点背景知识:
我们有几个虚拟服务器配置为中间代理,其中一个客户端可以启动到虚拟服务器的 RDP 会话,并在那里启动应用程序。 该应用程序从数据库读取连接数据,包括用于连接到最终目标计算机的用户名和密码。
对于远程桌面会话,我们使用从 MSTSCAX.DLL 中提取的 ActiveX 控件(使用 AxImp)。 由于用户无权访问远程计算机的密码,因此我们绝对必须防止会话超时。
在过去的几个月里,我们一直使用以下由 Timer 对象触发的代码来完成此任务。 这非常有效,直到我必须将 RDP 客户端升级到版本 6 才能访问 Server 2008 盒子(我们使用的是版本 4 或 5,不确定是哪一个)。 从那时起,对 SendKeys 的调用有时会抛出 HRESULT E_FAIL 错误 - 通常足以导致重大问题。
有谁知道可能是什么原因造成的? 更好的是,是否有人有更好的方法来完成此操作,并且可以与较新的 RDP 客户端配合使用?
谢谢, 戴夫
_mstscKeyControl = (IMsRdpClientNonScriptable)_mstsc.GetOcx();
private void KeepAlive()
{
try
{
if ( null != _mstsc && 0 != _mstsc.Connected )
{
bool[] bKeyUp = new bool[ 20 ];
int[] KeyData = new int[ 20 ]; // value matches lParam parameter of WM_DOWN message
/*
* Send CAPS LOCK on followed by OFF
*
* The SendKeys routine will not allow remote data in a single call to be mixed with
* local data so this shouldn't mess up anything.
*/
KeyData[ 0 ] = (int)MapVirtualKey( 14, 0 ); // vk_capital = CAPS LOCK
bKeyUp[ 0 ] = false;
KeyData[ 1 ] = KeyData[ 0 ];
bKeyUp[ 1 ] = true;
_mstscKeyControl.SendKeys( 2, ref bKeyUp[ 0 ], ref KeyData[ 0 ] );
}
}
catch ( Exception ex )
{
MessageBox.Show( ex.Message + Environment.NewLine + ex.StackTrace );
}
}
For our Secure Terminal Server project, we have a need to keep the RDP session open, that is, to prevent the remote computer from timing out and locking the session. A little background:
We have several virtual servers configured as go-between agents, with a client piece that launches a RDP session to the virtual servers, and starts an application there. That application reads connection data from a database, including the username and password for connecting on to the final destination computer.
For remote desktop sessions, we use the ActiveX control extracted from MSTSCAX.DLL (using AxImp). Because the user does not have access to the password for the remote machine, we absolutely must keep the session from timing out.
For the past several months, we have been using the following code, triggered by a Timer object, to accomplish this. That worked great, until I had to upgrade the RDP client to version 6 in order to access Server 2008 boxes (we were using version 4 or 5, not sure which). Since then, the call to SendKeys will sometimes throw an HRESULT E_FAIL error -- often enough to cause major problems.
Does anyone have an idea as to what may be causing this? Better yet, does anyone have a better way to accomplish this that may work with the newer RDP client?
Thanks,
Dave
_mstscKeyControl = (IMsRdpClientNonScriptable)_mstsc.GetOcx();
private void KeepAlive()
{
try
{
if ( null != _mstsc && 0 != _mstsc.Connected )
{
bool[] bKeyUp = new bool[ 20 ];
int[] KeyData = new int[ 20 ]; // value matches lParam parameter of WM_DOWN message
/*
* Send CAPS LOCK on followed by OFF
*
* The SendKeys routine will not allow remote data in a single call to be mixed with
* local data so this shouldn't mess up anything.
*/
KeyData[ 0 ] = (int)MapVirtualKey( 14, 0 ); // vk_capital = CAPS LOCK
bKeyUp[ 0 ] = false;
KeyData[ 1 ] = KeyData[ 0 ];
bKeyUp[ 1 ] = true;
_mstscKeyControl.SendKeys( 2, ref bKeyUp[ 0 ], ref KeyData[ 0 ] );
}
}
catch ( Exception ex )
{
MessageBox.Show( ex.Message + Environment.NewLine + ex.StackTrace );
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过管理组策略来配置终端服务并保留会话处于活动状态吗?
Have you tried managing Group Policies to configure Terminal Services and keep the session active?
有没有办法代替 sendkeys 来传递某种 mousemove ? 我怀疑如果您只将鼠标移动几个像素,那么侵入性会更小。 不过,我不确定 RDP 是否有某种鼠标移动阈值 - 也许几个像素不足以重置断开/锁定超时。
我们最终也会遇到同样的问题(我们的终端服务器当前是 2003 年,但我们会在某个时候升级到 2008 年),所以我真的很想知道您的解决方案最终是什么。
Instead of a sendkeys, is there a way to pass some kind of mousemove instead? I suspect this would be less invasive, if you only move the mouse a few pixels. I'm not sure if RDP has some kind of mouse movement threshold, though - maybe a few pixels isn't enough for it to reset the disconnect/lock timeout.
We'll eventually have this same problem (our terminal server is currently 2003, but we'll upgrade to 2008 at some point), so I'd really be interested to know what your solution ends up being.
我也有同样的需要,让 RDP 6 从客户端保持活动状态。 通过谷歌来到这里,尝试了 sendkey 和 mousemove,但没有成功。 结果
WM_ACTIVATE
就可以解决问题。这是我的基本
AutoHotkey
脚本段:RemoteMachine_Tick:
I have the same need to keep RDP 6 alive from the client side. Came here via google, tried sendkey and mousemove, didn't work. Turn out
WM_ACTIVATE
do the trick.Here's my basic
AutoHotkey
script segment:RemoteMachine_Tick: