1

I am working on a kiosk application which gives the user a selection of Citrix connections.

The idea is that the user selects a connection presented by the kiosk application, and then the kiosk launcher initiates the selected connection by running a command similar to this:

C:\Program Files\Citrix\ICA Client\wfica32.exe \\server\path\to\icaFile.ica

I want the user to stay within the Citrix session - not for any security reason, just to make it a good user experience getting to the selected session and eventually logging off. So I launch a full-screen session and everything is fine until the user logs off.

When the user logs off the Citrix session, I want to also initiate a logoff on the client computer. I've tried doing this in the obvious way by using code similar to the following:

Process citrixProcess = new Process();
citrixProcess.StartInfo = new ProcessStartInfo();
citrixProcess.StartInfo.FileName = "C:\Program Files\Citrix\ICA Client\wfica32.exe";
citrixProcess.StartInfo.Arguments = "\\server\path\to\icaFile.ica";
citrixProcess.Start();
citrixProcess.WaitForExit();
//
// Followed by code to initiate logoff from the local computer
//

But instead of waiting on the Process object the code continues right along to the next section which initiates the logoff. The result is that the Citrix session is terminated almost immediately because a local computer logoff happens immediately. My best guess is that the initial launch of wfica32.exe is exiting immediately after launching a new process to actually handle the session. But if this is what is happening it is not obvious what to do about it since wfica32.exe still appears to be running once the Citrix session is launched.

I am looking for a reliable way to detect when a Citrix session launched this way has terminated.

Shannon Wagner
  • 361
  • 7
  • 25

1 Answers1

4

In a C# Application you can reference WFICALib.dll (in your Citrix Ica Client folder), create an ICAClientClass object, subscribe to the and call it's Disconnect event, and call the LoadIcaFile method to launch your connection.

In your handler for the Disconnect method you would need to add code to initiate the log-off and terminate the current application.

An example implementation:

public static void Connect()
{
    // Configure the connection.
    ICAClientClass ica = new ICAClientClass();
    ica.Application = string.Empty;
    ica.InitialProgram = "#Name of Citrix application to launch";
    ica.Launch = true;
    ica.Domain = Environment.UserDomainName;
    ica.DesiredColor = ICAColorDepth.Color24Bit;
    ica.OutputMode = OutputMode.OutputModeNormal;
    ica.MaximizeWindow();
    ica.ClientAudio = true;
    ica.AudioBandwidthLimit = ICASoundQuality.SoundQualityMedium;
    ica.Compress = true;
    ica.ScreenPercent = 100;
    ica.TransportDriver = "TCP/IP";
    ica.WinstationDriver = "ICA 3.0";
    ica.SSLEnable = false;
    ica.SSLCiphers = "ALL";
    ica.SSLProxyHost = "*:443";
    ica.EncryptionLevelSession = "EncRC5-128";

    // Citrix server name or IP
    ica.Address = "x.x.x.x"; 

    // Setup handler for disconnect event.
    ica.OnDisconnect += ica_OnDisconnect;

    // Initiate the connection.
    ica.Connect();
}

private static void ica_OnDisconnect()
{
    Console.WriteLine("ica_OnDisconnect");
}
Shannon Wagner
  • 361
  • 7
  • 25
Peter T. LaComb Jr.
  • 2,935
  • 2
  • 29
  • 44
  • Thank you so much. I will plan to look at the documentation for this component and try it out, hopefully in the next few weeks when I get back to that project. Much appreciated! – Shannon Wagner May 22 '12 at 14:14
  • 1
    The documentation is kind of sparse, but I'm working on a related application and I would be happy to share anything I can and update the answer or related questions. – Peter T. LaComb Jr. May 22 '12 at 17:41
  • 1
    This was what really got me started on the right path: http://blogs.citrix.com/2010/03/02/fun-with-the-ica-client-object-ico-and-net-console-applications/ – Peter T. LaComb Jr. Jun 05 '12 at 13:48
  • Hey, thanks - very much appreciate the follow-up. I'm sure the sample code in the linked blog post will be helpful. – Shannon Wagner Jun 05 '12 at 14:00
  • Finally getting back to this. I got a prototype working and added some sample code to your answer based on what worked for me. I know there are a lot of properties you can set on the object - I based my code mostly on the property values I found in an ICA file that was working. Unfortunately I was not yet able to get the code working with the LoadIcaFile() method - not sure why. Please feel free to edit my sample... – Shannon Wagner Jun 27 '12 at 14:37
  • When I called LoadIcaFile(), nothing seemed to happen. I am going to try to take a look at it more this week but since it wasn't clear what was failing I decided to work with setting the properties directly instead. The downside of the way I am doing it now is that I need to write code to attempt each server that the ICA file specifies and then detect whether there is success logging on. There are a few failed logon cases that I am having trouble catching via an event - working through those this week (might post some sample code in a new question...). – Shannon Wagner Jul 01 '12 at 09:42