Client side XENAPP Session enumeration and selective logoff based on XenApp Server using ICA Client Object (WFICALib)

In my previous post i used AutoIt script to achieve this and now finally figured out to do it using ICA Client Object (WFICALib)


#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)

#Use Program Files (x86) for x64 bit machines
[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 "XA-WIN2K8-EPIC*")
      {
        "EPIC Session Found running on $AppSERVER; logging off"
        $ICO.Logoff()
      }
      $ICO.StopMonitoringCCMSession($sessionid);     
}
$ICO.CloseEnumHandle($EnumHandle)


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/

2 thoughts on “Client side XENAPP Session enumeration and selective logoff based on XenApp Server using ICA Client Object (WFICALib)

  1. This is exactly what we was looking for! You really saved our bacon this time Smulpy! To avoid setting the registry keys we ended up executing the ica file inside our application using the LoadIcaFile() and Connect(). This allowed us to later Logoff() the session which was our initial headache. Keep up the good work and keep sharing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s