title: Detecting a Citrix XenDesktop Session
body: <p>I'm looking to determine if our application is running on a XenDesktop session rather than locally. Here is what I have found so far:</p>
  
  <hr>
  
  <p>We currently have code to detect a Citrix XenApp session similar to the solution mentioned by Helge Klein in "<a href="https://stackoverflow.com/a/4188982/1055765">API for Determining if App is Running on Citrix or Terminal Services</a>".</p>
  
  <p>Sadly that solution in a XenDesktop environment is returning back a <code>WTSClientProtocolType</code> of <code>0</code> which signifies a local console session.</p>
  
  <p>In response to the same question Josh Weatherly mentioned checking the sessionname environment variable. </p>
  
  <p>However a quick console check with <code>echo %sessionname%</code> on the XenDesktop environment returns back 'Console'.</p>
  
  <p>From "<a href="https://stackoverflow.com/a/304867/1055765">Detect citrix “application mode”?</a>" John Sibly suggested a solution for detecting a remote session (not Citrix in particular):</p>
  
  <p><code>GetSystemMetrics(SM_REMOTESESSION)</code> however returns 0 which also means that it is a local session.</p>
  
  <hr>
  
  <p>Does anyone know of a way to detect that it is a XenDesktop session? So far as you can see all my attempts are returning that the session is a local console session.</p>
  
  <p>I'm using XenDesktop Express 5.5, accessing the desktop using the Citrix Receiver Web Plug-In.</p>