26 Sep 2012: See my updated method here.
I have been modifying a client’s 2500 line VBScript login script recently (what a beast!) and had to find a replacement for ICACLIENTINFO.EXE which was used in their Presentation Server 4.0 environment to determine the client IP address and map printers based on subnet. ICACLIENTINFO.EXE does not work with XenApp 6/6.5, so I had to find a replacement method. After some hunting through the registry I found this:
HKLM\SOFTWARE\Citrix\Ica\Session\2\Connection\ClientAddress
Now I just had to find a way to determine the Session ID, which was easier than I thought:
HKCU\Volatile Environment\2
And now to put it together into a script:
Set objShell = CreateObject(“Wscript.Shell”)
aRegKeys = RegEnum(“.”, “HKCU”, “Volatile Environment”)
sessionID = aRegKeys(0)
strIPCTXClient = objShell.RegRead(“HKEY_LOCAL_MACHINE\SOFTWARE\Citrix\Ica\Session\” & sessionID & “\Connection\ClientAddress”)
WScript.Echo “Client IP Address: ” & strIPCTXClient
‘************************************************************************
‘*
‘* Function RegEnum()
‘*
‘* Purpose:Enumerate all subkeys of the specified registry key.
‘*
‘* Input:strHkey – registry hive (HKLM, HKCU etc)
‘* strKey – the registry key to enumerate
‘*
‘* Output: An array of the subkeys. An empty array is returned for an error.
‘*
‘************************************************************************
Function RegEnum(strTarget, strHkey, strKey)
Const VBObjectError = -2147221504
Const FUNCTIONNAME = “RegEnum ()”
Dim intHkey
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
Select Case UCase(strHkey)
Case “HKCR”
intHkey = HKEY_CLASSES_ROOT
Case “HKCU”
intHkey = HKEY_CURRENT_USER
Case “HKLM”
intHkey = HKEY_LOCAL_MACHINE
Case “HKU”
intHkey = HKEY_USERS
Case “HKCC”
intHkey = HKEY_CURRENT_CONFIG
Case Else
Err.Raise vbObjectError, FUNCTIONNAME, “Invalid HKEY: ” & strHkey
RegEnum = Array()
Exit Function
End Select
On Error Resume Next
Dim objReg
Set objReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\”&_
strTarget & “\root\default:StdRegProv”)
If Err <> 0 Then
RegEnum = Array()
Exit Function
End If
‘ Get all subkeys in the specified key
Dim arrSubKeys
objReg.EnumKey intHkey, strKey, arrSubKeys
If Err <> 0 Then
RegEnum = Array()
Exit Function
End If
If IsArray(arrSubKeys) Then
RegEnum = arrSubKeys
Else
RegEnum = Array()
End If
End Function
Location
Deptive - Commercial Bay
11-19 Customs Street West St
Commercial Bay Tower, Level 17, Room 1715
Auckland 1010
We also have a virtual office in Wellington.
Contact Details
0800 000 141
Postal Address
PO Box 34797,
Birkenhead, Auckland 0746
5 Comments
Here is another way
Set objCTXWMIService = GetObject(“winmgmts:\localhostrootcitrixhdx”)
Set colCTXItems = objCTXWMIService.ExecQuery(“Select ClientIP from Citrix_Sessions”)
For Each objItem in colCTXItems
ClientIP = Cstr (objItem.ClientIP)
objClientName = Cstr (objItem.ClientName)
Next
Thanks for the script, do you know if this works only with newer clients?
Hi,
You should have convinced the client to use Group Policy Preferences, which is far easier way and can allow so many conditional variation.
I personally have used this for my organisation highly mobile work workforce, the default printer is mapped on IP subnet address.
Best of all it’s free!
I am a big fan of GPP and use it extensively, however this client was not ready to “move on”!!
This has been very useful to me. Thank you.