I'm working on an application that records the screen and it should support terminal services, The problem is actually when the RDP window is minimized the user session goes into UI less mode and there is no screen to capture for the application running on that particular session.
There is a way to handle it by setting a registry value to hold on the UI as described here.
But I do not want to do that and would like to capture the UI less mode status and display the user a message that the RDP window had been minimized/fast user switch has happened and the recording is suspended.
So I decided to enumerate the active sessions and check whether the user session is either idle or UI lesss. But that doesn't help. I did not find any clue about detecting the fast user switch when the RDP window is minimzed after almost spending a day.
I couldn't find any event or an API that I can call to ensure that the screen capture has been failing due to fast user switch / minimized RDP window.
Here is my code,
bool bActive = false;
{
DWORD dwCurrentProcessSessionID = 0;
ProcessIdToSessionId(GetCurrentProcessId(), &dwCurrentProcessSessionID);
PWTS_SESSION_INFO pSessionInfo = 0;
DWORD dwCount = 0;
// Get the list of all terminal sessions
WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSessionInfo, &dwCount);
int dataSize = sizeof(WTS_SESSION_INFO);
// look over obtained list in search of the active session
for (DWORD i = 0; i < dwCount; ++i)
{
WTS_SESSION_INFO si = pSessionInfo[i];
if (_WTS_CONNECTSTATE_CLASS::WTSActive == si.State)
{
// If the current session is active – store its ID
if (dwCurrentProcessSessionID == si.SessionId)
{
// would like to have an API that can identify whether the current RDP session is UI less
if (FunctionToFindCurrentRDPIsUIless(si.SessionId))
{
bActive = false;
}
else
{
bActive = true;
}
break;
}
}
}
}
Any help would be appreciated.