I’ve been working on a solution to provide users with a self logoff button on the Citrix web Interface. The script shown here check for your session on all servers but theĀ  one your running the logoff script from until the end. So if you been looking for a simple way to just allow users to logoff or reset their own session then have a play with this bat script.

This example is for just 3 servers in a farm, hopefully this will just give you the basic idea and you can easier modify it to your enviroment.

Script

@SET TSXEN01=MYServer1

@SET TSXEN02=MyServer2

@SET TSXEN03=MyServer3

@IF %COMPUTERNAME%==%TSXEN01% GOTO KillTS02
@IF %COMPUTERNAME%==%TSXEN02% GOTO KillTS03
@IF %COMPUTERNAME%==%TSXEN03% GOTO KillTS01
@GOTO EOF

:KillTS02
@Echo Logging off Sessions
@FOR /F “tokens=3 skip=1” %%k in (‘query session %USERNAME% /SERVER:%TSXEN02%’) DO LOGOFF /SERVER:%TSXEN02% %%k
@FOR /F “tokens=3 skip=1” %%g in (‘query session %USERNAME% /SERVER:%TSXEN03%’) DO LOGOFF /SERVER:%TSXEN03% %%g
@FOR /F “tokens=3 skip=1” %%i in (‘query session %USERNAME% /SERVER:%TSXEN01%’) DO LOGOFF /SERVER:%TSXEN01% %%i
GOTO EOF

:KillTS03
@Echo Logging off sessions
@FOR /F “tokens=3 skip=1” %%k in (‘query session %USERNAME% /SERVER:%TSXEN02%’) DO LOGOFF /SERVER:%TSXEN03% %%k
@FOR /F “tokens=3 skip=1” %%g in (‘query session %USERNAME% /SERVER:%TSXEN03%’) DO LOGOFF /SERVER:%TSXEN01% %%g
@FOR /F “tokens=3 skip=1” %%i in (‘query session %USERNAME% /SERVER:%TSXEN01%’) DO LOGOFF /SERVER:%TSXEN02% %%i
@GOTO EOF

:KillTS01
@Echo Logging Off Sessions
@FOR /F “tokens=3 skip=1” %%k in (‘query session %USERNAME% /SERVER:%TSXEN02%’) DO LOGOFF /SERVER:%TSXEN01% %%k
@FOR /F “tokens=3 skip=1” %%g in (‘query session %USERNAME% /SERVER:%TSXEN03%’) DO LOGOFF /SERVER:%TSXEN02% %%g
@FOR /F “tokens=3 skip=1” %%i in (‘query session %USERNAME% /SERVER:%TSXEN01%’) DO LOGOFF /SERVER:%TSXEN03% %%i
@GOTO EOF

:EOF

END Script

This script was tested and used in a live enviroment, however there are no warranties.