I'm looking for an API/function I can call to determine if software is running on Citrix, Terminal Services, or a stand-alone PC. Optimally, it would work something like this:
Select Case APIWhatSystem.Type.ToString
Case "Citrix"
bCitrix = True
Case "TS"
bTerminalServices = True
Case "PC"
bPC = True
End Select
I would prefer something that worked from an API call as opposed to looking at something in the registry as we're having more and more customers that are locking down the registry.
Thanks.
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:
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:
WTSQuerySessionInformation
. If that returns 1 or 2 (ICA or RDP), you are done.WTSQuerySessionInformation
returns 0 (Console), dynamically load wfapi.dll
and get the address of WFGetActiveProtocol
WFGetActiveProtocol
with a parameter of WF_CURRENT_SESSION
, which is defined as ((DWORD)-1)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.
According to: http://forums.citrix.com/message.jspa?messageID=1363711 you can check the SESSIONNAME environment variable.
Another simpler way is to read the system environment variable "SESSIONNAME". If it exists and starts with "ICA" then you're running within a Citrix session. If it starts with "RDP" then you're running within an RDP session.
I tested it with my PC and locally I get:
C:\>echo %SESSIONNAME%
Console
While remotely I got
C:\>echo %SESSIONNAME%
RDP-tcp1
So it seems like it might be an easy route to go, otherwise it sounds like checking for registry values or if certain dlls exist will be the next best thing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With