UPDATE: How to determine Client IP Address in XenApp 6.5

Thanks to a very helpful comment from Kahless on my previous post on this topic, I have developed a new method of obtaining the client IP address from a script running on the XenApp 6 or XenApp 6.5 server.

This only works on XenApp 6.5

This script uses the SESSIONNAME environment variable to return the ClientIP via WMI.

Function GetCTXClientIP
Set ObjShell = CreateObject(“Wscript.Shell”)
Dim strSessionName : strSessionName = ObjShell.ExpandEnvironmentStrings( “%SESSIONNAME%” )
Dim objCTXWMIService : Set objCTXWMIService = GetObject(“winmgmts:\\localhost\root\citrix\hdx”)
Dim colCTXItems : Set colCTXItems = objCTXWMIService.ExecQuery(“Select ClientIP from Citrix_Sessions where StationName = ‘” & strSessionName & “‘”)
Dim objItem, ClientIP

For Each objItem in colCTXItems
ClientIP = Cstr (objItem.ClientIP)

GetCTXClientIP = ClientIP
End Function


  1. The problem is that environment variables are sometimes empty during logon/logoff on W2008R2 SP1.
    The same occurs for the %SESSIONNAME%. Means the script is useless as logon/logoff script.

    Getting session from TMP folder doesn’t work.
    Running CLientnfo.exe during logon result in disconnect.
    Getting volatile env. is also untrustable.

    Other solution?


  2. Jason Poyner says:

    We have this script running as a logon script to map printers based on the client IP address so I can confirm is does work as a logon script.
    How have you determined that the %SESSIONNAME% variable is not present?

  3. Rob Nicholson says:

    Related problem – ever since we switched to XenApp 6.5 on W2k8 R2 from XenApp 5 on Windows 2003, the CLIENTNAME environment variable is blank during logon script but is set if you check later via cmd.exe

Leave a Reply

Contact Deptive

Level 13 (Regus)
92 Albert St
We also have a virtual office in Wellington.

Contact Details

0800 000 141

Postal Address
PO Box 34797,
Birkenhead, Auckland 0746