Easiest thing would be

 Code:
if @tssession
    exit 1
endif


at the beginning of your script, but that would also exit on rdp sessions...
_________________________