Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C++

WM6.1: Remote Desktop Client disconnects after 10 minutes

0.00/5 (No votes)
4 Jan 2010CPOL 14.1K  
Unfortunately Remote Desktop Mobile (RDM) Client, if part of your Windows Mobile 6.1 device, will disconnect after 10 minutes of user idle time...

Unfortunately Remote Desktop Mobile (RDM) Client, if part of your Windows Mobile 6.1 device, will disconnect after 10 minutes of user idle time. This value seems to be hardcoded into the application. Various searches on the internet lead to this assumption. So regardless of your server or client settings, RDM will disconnect after 10 minutes of user idle.

RDM_IdleTimeout

The following code is from this blog. For those of you not being able to compile the code, I have attached an ArmV4i executable you can use directly on your device.

Here is the code:

C++
// RDMkeepBusy.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
#include
#include 
 
int _tmain(int argc, _TCHAR* argv[])
{
    int const FIVEMINUTES = 1000*60*5; //1000 ms
    HWND hWndRDM = NULL;
 
	//First check if TSC is already running???
 
    //Firstly launch RDP Client
    SHELLEXECUTEINFO sei = {0};
    sei.cbSize = sizeof(sei);
    sei.nShow = SW_SHOWNORMAL;
    sei.lpFile = TEXT("\\Windows\\wpctsc.exe");
    sei.lpParameters = TEXT(" ");
    if (!ShellExecuteEx(&sei))
    {
        MessageBox(NULL, TEXT("Couldn't launch RDP Client"), 
	TEXT("Remote Desktop Launcher"), MB_OK | MB_TOPMOST | MB_SETFOREGROUND);
        goto Exit;
    }
	else
		Sleep(500);
 
    //Now every X minutes check if it's still running and if so "refresh" its window
    //if it's no longer running, exit
    do
    {
        //check if RDP Client is running, otherwise exit
		DEBUGMSG(1, (L"FindWindow 'TSSHELLWND'...\n"));
        hWndRDM = FindWindow(_T("TSSHELLWND"), NULL);
        if (NULL != hWndRDM)
        {
            ////Get foreground window -- this is not needed 
	   ///if RDM is launched Full-Screen as it was in this case
            //hWndForeground = GetForegroundWindow();
            //Sleep(500);
 
            //Give focus to the RDP Client window (even if the logon screen, 
            //in case user logged out in the meantime)
			DEBUGMSG(1, (L"SetForGroundWindow\n"));
            SetForegroundWindow(hWndRDM);
 
            //The timer is reset when the rdp window receives mouse or keyboard input
            //with no MOUSEEVENTF_ABSOLUTE the move is relative
 
			DEBUGMSG(1, (L"MOUSEEVENTF_MOVE 1\n"));
            mouse_event(MOUSEEVENTF_MOVE, 100, 0, 0, 0);
            Sleep(250);
			DEBUGMSG(1, (L"MOUSEEVENTF_MOVE 2\n"));
            mouse_event(MOUSEEVENTF_MOVE, -100, 0, 0, 0);
 
            ////Give focus back to previous foreground window
            //SetForegroundWindow(hWndForeground);
 
            //Sleep
			DEBUGMSG(1, (L"Sleep ...\n"));
            Sleep(FIVEMINUTES);
        }
        else
        {
			DEBUGMSG(1, (L"FindWindow failed for 'TSSHELLWND'\n"));
            //RDP Client is not running - let's exit
            goto Exit;
        }
    }
    while (TRUE); //The check (NULL != hWndRDM) is already done inside the loop
 
Exit:
	DEBUGMSG(1, (L"Exit!\n"));
    if (NULL != hWndRDM)
        CloseHandle(hWndRDM);
 
    return 0;
}

<!-- Social Bookmarks BEGIN -->

<!-- Social Bookmarks END -->

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)