(KiX Master)
2003-02-14 04:34 PM
Citrix and/or Terminal Server Client Collection

Citrix and/or Terminal Server Client Collection

First off, I would like to explain...
In the case of thin (Citrix or Terminal Server) clients, KiX always runs in the memory space of the server so all the standard queries and macros report on the server and not on the client. One generally does not want a logon script to run on a Terminal Server so there needs to be a method to determine and subvert the script.

Perhaps the simplest is to just check for any server and abort, assuming that one does not want their script to run on any server whatsoever. This can be done by reading the ProductType out of the registry.

;  - check if logon to Wintendo or WinNT
; @InWin - 1 = Windows NT; 2 = Windows 9x
; - check if logon to Server or Workstation
; PRODUCTTYPE - WinNT = Workstation, ServerNT = Member Server, LanmanNT = Domain Controller
IF @InWin = 1 ;Not Wintendo
; if not Workstation, just exit without notice
Exit 1

Alternately, if the broad brush approach won't do...

How to determine that KiX is running on a Terminal Server
KiX has the @ProductSuite macro that returns the bitwise sum of the following possible Values:
00000000001 - 1 "Small Business"
00000000010 - 2 "Enterprise"
00000000100 - 4 "BackOffice"
00000001000 - 8 "CommunicationServer"
00000010000 - 16 "Terminal Server"
00000100000 - 32 "Small Business (Restricted)"
00001000000 - 64 "Embedded NT"
00010000000 - 128 "DataCenter"
00100000000 - 256 "Single User Terminal Server"
01000000000 - 512 "Home Edition"
10000000000 - 1024 "Blade Server"

If you don't understand binary math then shame on you - go back to computers 101 - do not pass GO.

So then, a Windows 2000 Advanced Server with Terminal Services in 'Application' mode should return the value '18' which is the sum of:
2 "Enterprise"
16 "Terminal Server"

Windows 2000 Server (not Advanced) with Terminal Services in 'Remote Administration' mode should return the value '272' which is the sum of:
16 "Terminal Server"
256 "Single User Terminal Server"

A Windows XP Pro with Remote Desktop enabled should return the value '256' since it doesn't match any of the other bits.

@ProductSuite was first released in KiX 4.00 but it inadvertently returned a string VarType. Many people played with it and gave up on it (myself included) when they could not get the bitwise AND '&' to work. The smarter ones did figure it out and converted the VarType with Val(). I am not too embarassed to admit that I was not one of the smart ones, only recently discovering it. Ruud has now changed @ProductSuite in 4.20 to return an integer.

So then, in a nutshell:
If Val(@ProductSuite) & 16
"It is a Terminal Server in 'Application' or 'Remote Administration' mode" ?

or Howard's UDF:
Function ProductSuite ($Product)
Dim $Product

case $Product = "None" $x=0
case $Product = "Small Business" $x=1
case $Product = "Enterprise" $x=2
case $Product = "BackOffice" $x=4
case $Product = "CommunicationServer" $x=8
case $Product = "Terminal Server" $x=16
case $Product = "Small Business (Restricted)" $x=32
case $Product = "Embedded NT" $x=64
case $Product = "DataCenter" $x=128
case $Product = "Single User Terminal Server" $x=256
case $Product = "Home Edition" $x=512
case $Product = "Blade Server" $x=1024
case 1 $RC=MessageBox ("Invalid parameter used in function ProductSuite ($Product)",48)
WriteLog("Invalid parameter used in function ProductSuite ($Product)")

$ProductSuite = $x & val(@ProductSuite)

if ProductSuite("Terminal Server") and not ProductSuite("Single User Terminal Server")

(KiX Master)
2003-02-14 10:19 PM
Re: Citrix and/or Terminal Server Client Collection

Getting Client Details

There is often a need to get specific information from the thin client that is logging on to a Terminal Server. To that end, there are several environment variables that are available.

While in a Terminal Server session, spark up a DOS box and enter the command SET. Some of the vars of interest are:

%CLIENTNAME% - This is the thin client's NetBIOS name.

%SESSIONNAME% - This would be 'CONSOLE' if logged on at the console or something like 'ICA-tcp#16' if via an ICA session.

The remaining environment vars are your standard NT vars, non-specific to Terminal Services.

If you require additional information then that will require some helper apps or DLL libraries. This I will cover in the next post.

(KiX Master)
2003-02-14 11:04 PM
Re: Citrix and/or Terminal Server Client Collection

Helper Apps and Libraries

There have been several helper apps and libraries written to facilitate the extraction of more client details. Two of them are written with the Citrix SDK and therefore require Citrix. You need to delve into them to determine what is best for your need.

WTSManager.dll does not require Citrix but does require that the DLL be registered.

Win32Admin.DLL provides a COM interface to many useful Win32 commands not available in KiXtart.

Documentation accompanies the apps and libraries.

The following links are where you can find these helpers.

wtsmanager.zip from KiXhelp.com

(KiX Master)
2006-11-03 04:25 AM
Re: Citrix and/or Terminal Server Client Collection

Since the above FAQ was written, Ruud has added the @TSSession macro but it does not do anything better than what is already mentioned.