For our Secure Terminal Server project, we need to open an RDP session, i.e. prevent the remote computer from turning off the timer and blocking the session. A bit of background:
We have several virtual servers configured as intermediary agents, with the client part that starts the RDP session on the virtual servers and launches the application there. This application reads the connection data from the database, including the username and password for connecting to the destination destination computer.
For remote desktop sessions, we use an ActiveX control extracted from MSTSCAX.DLL (using AxImp). Since the user does not have access to the password for the remote machine, we absolutely must disconnect the session.
Over the past few months, we have used the following code initiated by the Timer object to execute this. This worked great until I had to upgrade the RDP client to version 6 to access Server 2008 windows (we used version 4 or 5, not sure which one). Since then, the SendKeys call has occasionally raised the HRESULT E_FAIL error - often enough to cause serious problems.
Does anyone have any ideas as to what could be causing this? Even better, is there anyone better way to accomplish this that might work with the new 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 ];
KeyData[ 0 ] = (int)MapVirtualKey( 14, 0 );
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 );
}
}
source
share