Get the ClientAddress (IP) under Citrix

garakgarak Member Posts: 3,263
edited 2005-12-15 in NAV Tips & Tricks
When you are working under citrix and you need the clientaddress of the connected users (the local IPs of the connected Client Pcs) you can do this with 2 Options:

1. You use the 'Citrix MetaFrame COM Library'

This example shows all session and the connected Clientaddress, Clientname and Usernames

Variables
Name	DataType	Subtype	Length
MetaFrameFarm	Automation	'Citrix MetaFrame COM Library'.MetaFrameFarm	
MetaFrameWinFarm	Automation	'Citrix MetaFrame COM Library'.IMetaFrameWinFarm6	
IMetaFrameSessions	Automation	'Citrix MetaFrame COM Library'.IMetaFrameSessions	
IMetaFrameSession	Automation	'Citrix MetaFrame COM Library'.IMetaFrameSession	
SessionCounts	Integer		
i	Integer		



IF ISCLEAR(MetaFrameFarm) THEN
  CREATE(MetaFrameFarm);

MetaFrameFarm.Initialize(1);

MetaFrameWinFarm := MetaFrameFarm.WinFarmObject;
if MetaFrameWinFarm.IsCitrixAdministrator = 0 then
  error('Not an Citrix Admin ;-(');

IMetaFrameSessions := MetaFrameFarm.Sessions;

SessionCounts := IMetaFrameSessions.Count();



MESSAGE(FORMAT(SessionCounts));

FOR i := 0 TO SessionCounts-1 DO BEGIN
  
  IMetaFrameSession := IMetaFrameSessions.Item(i);
  MESSAGE('USER %1\ClientName %2\ClientAddress %3',
          IMetaFrameSession.UserName,
          IMetaFrameSession.ClientName,
          IMetaFrameSession.ClientAddress);
END;

clear(MetaFrameFarm);

The Problem here is, to run the code, you must be an Citrix Admin :(

An other way is to use the "WTSManager.dll"
variables

Name	DataType	Subtype	Length
WTSManager	Automation	'WTSManager Library'.Shell	
Counts	Integer		
i	Integer		
IP	Variant		
ClientName	Variant		



IF ISCLEAR(WTSManager) THEN
  CREATE(WTSManager);

Counts := WTSManagerP.ClientCount;
FOR i := 1 TO Counts DO BEGIN
  WTSManager.Refresh();
  IP := WTSManager.Clients(i).IPAddress;
  WTSManager.Refresh();
  ClientName := WTSManager.Clients(i).ClientName;

  IF (FORMAT(IP) <> '') THEN BEGIN
    MESSAGE('IP = %1\Clientname = %2',IP,ClientName);
    //LogOnUsers.INIT;
    //LogOnUsers."Report ID" := i;
    //LogOnUsers."Client IP" := IP;
    //LogOnUsers."Client Name" := ClientName;   
    //LogOnUsers.INSERT;

  END;
END;

CLEAR(WTSManager);

Regards
Do you make it right, it works too!
Sign In or Register to comment.