0

I have a C# WPF application that can run under 2 modes. The first is over Citrix, and the next is installed and running straight locally.

This app is old, and we were using a call to the windows remote desktop API, WTSQuerySessionInformation to work out whether we were running over Citrix or not.

https://msdn.microsoft.com/en-us/library/aa383838(v=vs.85).aspx

The call was basically this,

hRet = WTSQuerySessionInformation(WF_CURRENT_SERVER_HANDLE, WF_CURRENT_SESSION,
            WTS_INFO_CLASS.WTSApplicationName, ref ppBuffer, ref iBytesReturned);

So it was returning the application name on the current remote desktop session, and the assumption was that if there was no application name then it wasn't running under Citrix.

This is no longer working since we upgrade the version of Citrix we are using. The call above returns an empty string.

The questions are,

  1. Why is this call not working
  2. Is there a better way to work out whether a C# app is running over Citrix or not?
peter
  • 11,559
  • 18
  • 75
  • 138
  • Maybe 'feature detection' would be a better choice than 'environment detection' for your case. But without knowing why you need those two modes, I can not guess. I mean, for example, [detect whether 3D acceleration is available or not](http://stackoverflow.com/a/149802/1178314), if this is the lack of it which is the underlying reason for your need. – Frédéric Oct 07 '15 at 20:56
  • It is much more simple than that. If it is running on the local machine the app needs to read some files from a specific place on the local machine. If it is running over citrix it needs to load the same files from a shared drive. – peter Oct 07 '15 at 21:59
  • If the app on server is required to fetch the file remotely even if a session is locally opened on server for launching it (supposing it is possible with your servers), then the file path could be handled in a local config file / registry key. – Frédéric Oct 08 '15 at 13:26

2 Answers2

0

Sticking with the original method works, but instead of querying the WTSApplicationName I am querying the WTSClientProtocolType.

So I call WTSQuerySessionInformation with 3rd parameter set to WTSClientProtocolType. And this returns,

0 for console sessions
1 for ICA sessions
2 for RDP sessions
peter
  • 11,559
  • 18
  • 75
  • 138
-1

We use this:

var sessionName = (Environment.GetEnvironmentVariable("SessionName") ?? "").ToUpper();
return sessionName.StartsWith("ICA") || sessionName.StartsWith("RDP");

Where ICA infers Citrix, RDP remote desktop.

Andreas Rejbrand
  • 95,177
  • 8
  • 253
  • 351
James Willock
  • 1,859
  • 12
  • 16