There is an API function that lets you determine whether a specific user session is displayed on the console (locally) or via one the the remoting protocols Citrix ICA (nowadays called HDX) or Microsoft RDP.
Call WTSQuerySessionInformation with 3rd parameter set to WTSClientProtocolType. The function returns:
- 0 for console sessions
- 1 for ICA sessions
- 2 for RDP sessions
Interestingly the return value of 1 is not documented as WTS_PROTOCOL_TYPE_ICA
on MSDN (second link above) any more, but as “This value is retained for legacy purposes.”.
Update:
XenDesktop sessions cannot be detected with WTSQuerySessionInformation
(it returns 0, meaning Console). If you want a universal solution:
- Call
WTSQuerySessionInformation
. If that returns 1 or 2 (ICA or RDP), you are done. - If
WTSQuerySessionInformation
returns 0 (Console), dynamically loadwfapi.dll
and get the address ofWFGetActiveProtocol
- Call
WFGetActiveProtocol
with a parameter ofWF_CURRENT_SESSION
, which is defined as ((DWORD)-1) - The return value of
WFGetActiveProtocol
is the session type. It should be either 0 (Console) or 1 (ICA)
I have described the process in detail here along with a C++ code sample and a working compiled tool that returns the current session’s remoting protocol type.