Programmatically Logoff XenApp Sessions using Citrix Connection Center (ClientSide)

Update

visit Disconnect ICA session from inside, this method uses citrix api (more reliable).

Use Case

Certain published EMR applications are assigned privileges based on endpoint and they fail to reevaluate those privileges at smooth roam. In my scenario the published app is running inside XenDesktop Session and the work around is to logoff the XenApp Session and connect to a new session at smooth roam.

Problem

Citrix doesn’t provide any documented way of doing this programmatically(SDK); one way is to use pnagent.exe /logoff which closes all XenApp sessions and this is not an option for me.
Second way is to use functions from C:\Program Files\Citrix\ICA Client\CCMSDK.dll

  • CCMGetSessionInfo
  • CCMLogoffSession

I couldn’t get any further because these functions are undocumented. Hence this is not an option either 🙂
finally I refreshed my skills in UI testing and wrote an AutoIt script that handles this programmatically

AutoIt Script

Logic

  • Launch Connection Center
  • Getfocus on the Treeview control of Connection Center
  • Get all the child nodes of Activity (which are the names of the XenApp Servers)
  • Find a match and send right click command to that node, followed by 4 down arrow keys and one enter keystroke which initiate’s the logoff
  • Close Connection Center

Download

AutoIt-ConnectionCenter.au3

Resource

http://www.autoitscript.com/autoit3/docs/libfunctions

Notes

This script can be converted to standalone exe using Aut2exe
CTX127491 Session State Monitor Tool is used to check if the user smooth roamed or not.

Join the Conversation

4 Comments

    1. Thanks for link Andreas.
      logoff of all the sessions can also be achieved by pnagent.exe /logoff
      I finally found API’s to do a selective XenApp Server logoff on the client side using “C:\Program Files\Citrix\ICA Client\WfIcaLib.dll”. Will be posting it soon.

      1. [code language=”powershell”]
        #the following keys need to be set on 32bit machine; for x64 use wow6432node.
        #HKLM\Software\Citrix\ICA Client\CCM\AllowLiveMonitoring=1 (DWORD 32)
        #HKLM\Software\Citrix\ICA Client\CCM\AllowSimulationAPI=1 (DWORD 32)
        [System.Reflection.Assembly]::LoadFile("C:\Program Files\Citrix\ICA Client\WfIcaLib.dll")
        $ICO = New-Object WFICALib.ICAClientClass
        $ICO.OutputMode = [WFICALib.OutputMode]::OutputModeNormal
        $EnumHandle = $ICO.EnumerateCCMSessions()
        $NumSessions = $ICO.GetEnumNameCount($EnumHandle );
        #"Number of live CCM sessions are:" + $NumSessions.tostring()
        for( $index = 0; $index -lt $NumSessions ;$index++)
        {
        $sessionid = $ICO.GetEnumNameByIndex($EnumHandle, $index)
        $ICO.StartMonitoringCCMSession($sessionid,$true)
        $APPSERVER = $ICO.GetSessionString(0)
        if($AppSERVER -match "WKENAH*")
        {
        "EPIC Session Found running on $AppSERVER; logging off"
        $ICO.Logoff()
        }
        $ICO.StopMonitoringCCMSession($sessionid);
        }
        $ICO.CloseEnumHandle($EnumHandle)
        # References
        # ICA Client Object Changes in the Version 11.2 XenApp Plug-in http://support.citrix.com/article/ctx123616
        # ICA Client Object Reference Guide version 2.5, see: http://support.citrix.com/article/ctx114202
        # http://blogs.citrix.com/2010/03/02/fun-with-the-ica-client-object-ico-and-net-console-applications/
        # http://community.citrix.com/pages/viewpage.action?pageId=37388917
        # http://www.florisvanderploeg.com/ica-connections-using-powershell-part-3/
        [/code]

Leave a comment

Your email address will not be published. Required fields are marked *

WordPress Appliance - Powered by TurnKey Linux