Check for the environment variables CLIENTNAME or SESSIONAME. Both of these are specific to a terminal server session. If they're defined, you can assume they are logged in using TS.