Hi,
Ever wondered how to connect to already existing sessions on your client machine launched through various means like for example, PNA or Web Interface??
Use Live Monitoring to achieve it.

What is Live Monitoring?

Live Monitoring is a feature that provides a way using ICA Simulation SDK (CTX111945 – Citrix ICA Client Simulation API Specification Programmer’s Guide) to obtain sessions launched from other Launch methods other than ICO, for example, PN Agent or Web Interface.
This is also called Passive Monitoring.
With Live Monitoring, it is possible to send keyboard and mouse input to sessions launched from these other launchers using the ICA Simulation SDK interface.
This feature was made available in version 11.2 of the Plug-ins, with three new API’s implemented:
A. EnumerateCCMSessions: API to enumerate all the sessions running on the machine returning the list of session IDs.
B. StartMonitoringCCMSession: API to start the live monitoring. You must pass the session ID of the session which you want to monitor. Once this is done, it is then possible to use other ICA Simulation APIs.
C. StopMonitoringCCMSession: API to stop monitoring the session. When finished with monitoring, this API should be called. Doing so cleans up any resources used by
ICO.
The above methods can be called on the ICO object we create and then assign to any current session we wish to.

Let’s start off with an example:

Assume that you launched a Notepad session through PN Agent on your client.
Now the following example code illustrates how you get hold of that Notepad session into the ICO instance you create and monitor that session.
Since ICO is scriptable in a variety of languages like javascript, VBScript, C# etc., I am using C# code to illustrate the feature for now:
Be Careful

Before attempting to consume the Live Monitoring APIs you must be informed about another change that was introduced within the 11.2 client. There was added security to restrict access to the session object. Access is controlled via the client registry. The following HKLM\Software\Citrix\ICA Client\CCM key must be created (it’s not there by default). Under that key, create a DWORD with name: AllowSimulationAPI
Type: REG_DWORD
Data: 1

Value of 0 or 1 disables and enables access to the monitor session object. So make sure this is set properly otherwise, you would never succesfully get a non-zero EnumerationHandle

This program shows the basic use of livemonitoring API’s within an application :
//Create a new ICA Client object
ICAClient ICO = new ICAClient();


<strong>ICO.OutputMode = OutputMode.OutputModeNormal;</strong>
<div>//Get the integer handle to the sessions enumeration
int EnumHandle = ICO.EnumerateCCMSessions();
//Get the count of sessions running currently on trhe client
int NumSessions = ICO.GetEnumNameCount(EnumHandle );
Console.WriteLine("Number of live CCM sessions are:" + Convert.ToString(NumSessions));
//String to store the sessionID
string[] SessionIDs = new string[NumSessions];
Console.WriteLine("Session IDs for live sessions are:");
//Get session IDs into an array of strings
for( int index = 0; index&lt; NumSessions ;index++)
{
//Obtain the sessionID by calling GetEnumNameByIndex method
SessionIDs[index] = ICO.GetEnumNameByIndex(EnumHandle, index);
Console.WriteLine("SessionID["+index+"] : " + SessionIDs[index]);
}
//Start monitoring the current session with the above sessionID
ICO.StartMonitoringCCMSession(SessionIDs[0], true);</div>

Make sure you set the “Output mode” property on ICO appropriately as shown above. This may be the reason for error messages if not set properly.

So, after you call StartMonitoring CCMSession, you are free to put your logic on what to monitor inside the session (keyboard events, windowing events,mouse events appropriately).
Once you are done with session monitoring logic, you may call
ICO.StopMonitoringCCMSession(SessionIDs[0])
at the end to stop monitoring the session.

This can well be done through powershell too!
Hope this blog helps you!

Happy coding!!