Save code in real time with the new RDP client

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 ];            // 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 );
        }
    }
+3
source share
3 answers

sendkeys, - mousemove? , , . , RDP - , , , reset /.

( - 2003, - 2008 ), , .

+1

RDP 6 . google, sendkey mousemove, . WM_ACTIVATE .

AutoHotkey script:

SetTimer, RemoteMachine_Tick, 60000

RemoteMachine_Tick:

IfWinNotActive, remote01 - Remote Desktop 
    SendMessage, 0x006, 1, 0, , remote01 - Remote Desktop; 
    WM_ACTIVATE(0x006)  WA_ACTIVE(1)
return
+1

?

0

Source: https://habr.com/ru/post/1711677/


All Articles