How to Determine Whether C# App Running Under Citrix [duplicate]

拥有回忆 提交于 2019-12-08 10:46:55

问题


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?

回答1:


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



回答2:


We use this:

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

Where ICA infers Citrix, RDP remote desktop.



来源:https://stackoverflow.com/questions/33001915/how-to-determine-whether-c-sharp-app-running-under-citrix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!