问题
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,
- Why is this call not working
- 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