From e8fc7149645eba2071ee0bcd303b6c47b8e22782 Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Fri, 18 Feb 2011 20:32:43 +0000 Subject: [PATCH] - client: Fast User Switching does not change the session protocol to RDP when the active session is put into the background and a new one is brought into the foreground. It appears it is safe to use the connected state in addition to the protocol to detect when the session is no longer capable of processing GPU work lib/ win_util.cpp svn path=/trunk/boinc/; revision=23068 --- checkin_notes | 11 +++++++++++ lib/win_util.cpp | 47 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/checkin_notes b/checkin_notes index acfe3b9b20..452ee8b0f0 100644 --- a/checkin_notes +++ b/checkin_notes @@ -894,3 +894,14 @@ David 17 Feb 2011 gui_rpc_server_ops.cpp http_curl.cpp net_stats.cpp,h + +Rom 18 Feb 2011 + - client: Fast User Switching does not change the session protocol + to RDP when the active session is put into the background and + a new one is brought into the foreground. It appears it is safe + to use the connected state in addition to the protocol + to detect when the session is no longer capable of processing + GPU work + + lib/ + win_util.cpp diff --git a/lib/win_util.cpp b/lib/win_util.cpp index cf1a445f1d..53c1dd1860 100644 --- a/lib/win_util.cpp +++ b/lib/win_util.cpp @@ -849,7 +849,7 @@ void chdir_to_data_dir() { // return true if running under remote desktop -// (in which case CUDA apps don't work) +// (in which case CUDA and Stream apps don't work) // typedef BOOL (__stdcall *tWTSQSI)( IN HANDLE, IN DWORD, IN DWORD, OUT LPTSTR*, OUT DWORD* ); typedef VOID (__stdcall *tWTSFM)( IN PVOID ); @@ -860,6 +860,7 @@ bool is_remote_desktop() { static tWTSFM pWTSFM = NULL; LPTSTR pBuf = NULL; DWORD dwLength; + USHORT usProtocol, usConnectionState; if (!wtsapi32lib) { wtsapi32lib = LoadLibrary(_T("wtsapi32.dll")); @@ -869,14 +870,15 @@ bool is_remote_desktop() { } } - // WTSQuerySessionInformation( - // WTS_CURRENT_SERVER_HANDLE, - // WTS_CURRENT_SESSION, - // WTSClientProtocolType, - // &pBuf, - // &dwLength - // ); if (pWTSQSI) { + + // WTSQuerySessionInformation( + // WTS_CURRENT_SERVER_HANDLE, + // WTS_CURRENT_SESSION, + // WTSClientProtocolType, + // &pBuf, + // &dwLength + // ); if (pWTSQSI( (HANDLE)NULL, (DWORD)-1, @@ -884,10 +886,35 @@ bool is_remote_desktop() { &pBuf, &dwLength )) { - USHORT prot = *(USHORT*)pBuf; + usProtocol = *(USHORT*)pBuf; pWTSFM(pBuf); - if (prot == 2) return true; } + + // WTSQuerySessionInformation( + // WTS_CURRENT_SERVER_HANDLE, + // WTS_CURRENT_SESSION, + // WTSConnectState, + // &pBuf, + // &dwLength + // ); + if (pWTSQSI( + (HANDLE)NULL, + (DWORD)-1, + (DWORD)8, + &pBuf, + &dwLength + )) { + usConnectionState = *(USHORT*)pBuf; + pWTSFM(pBuf); + } + + // RDP Session implies Remote Desktop + if (usProtocol == 2) return true; + + // Fast User Switching keeps the protocol set to the console but changes + // the connected state to disconnected. + if ((usProtocol == 0) && (usConnectionState == 4)) return true; + } return false;