I've corrected the typo's in my example. Sorry - I must have lost a char when I cut/paste parts of the original script.

The problem with Mart's example is that it performs the Citrix detection and runs the command to set the environment var from Kix. This won't work because the value is set in the child environment of the Run/Shell command, where it will disappear when the comand ends. The environment var must be set BEFORE Kix runs. There's no benefit of detecting physical or XEX session state within kix for your requirement.

Further - my "IIF" example will work and will not require any additional logic.

When you are on a regular PC and run the login script, the %XDClientName% will be empty. This causes the IIF logic to evaluate to "FALSE" and return the @WKSTA value. The command run from the bat file (or not, if you add the detection process there) will insure that the environment variable is not set.

However, when you login to a Xen session, the batch file runs the command which successfully sets the environment var. When the Kix script runs, the IIF evaluates to TRUE and returns the environment variable.

Either way, the $computerprt will contain the name of the PHYSICAL computer that the user is sitting at. Take the first six chars and continue with your code to determine the location and map the printers.

Now, for diagnostics..
In your Batch file, BEFORE you call the Kix script, add the line
 Code:
Set > %TEMP%\%USERNAME%_env.txt
This will capture the user's login environment settings to a file. Go to that folder after you log in and open it. Verify that the XDClientName variable is defined, and if so, is defined the way you expect. If it isn't, you need to troubleshoot the XD4ClientName.exe command.

Add the line
 Code:
'XD Client Name: ' %XDClientName% @CRLF
to your Kix script to verify that it sees the proper var value. Add this just before the IIF statement in my example. Add another debug message after the IIF block to view the contents of the $computerprt var. The end result should be:
 Code:
'XD Client Name: ' %XDClientName% @CRLF
$ComputerPrt = IIf(%XDClientName%,%XDCLientName%,@WKSTA)
$ComputerPrt = Left($ComputerPrt, 6)
'ComputerPrt: $ComputerPrt @CRLF
If this doesn't work, post the contents of the %TEMP%\%USERNAME%_env.txt file and a screenshot of the debug messages from the code above.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D