Windows – Trigger event to fire when user connects to a terminal server

rdpscheduled-taskwindowswindows-server-2003windows-terminal-services

We have a (very) fragile software suite running on a server in our datacenter that requires a user to be logged in, but freaks out and crashes if the user logs in twice (resource contentions, all sorts of issues)

Due to its fragile nature, certain processes break all the time, requiring our support guys to connect to the machine via RDP and restart stuff. They connect via the generic account that is running in the open session, and disconnect instead of logging off.

Problem is, sometimes they don't end up connecting to the disconnected session, but instead spawn a new session, and the server subsequently fails.

I am looking for a way to detect, upon connecting/ logging in, if there is another RDP session on the machine and warn the user so disaster can be averted.

I would dearly love to chuck this machine out of a high window, but replacing the software is not an option at this point.

UPDATE

In the end, I implemented both solutions. This works swimmingly.

Best Answer

One approach may be to run a logon script that connects them to the disconnected session instead of requiring some action on their part.

SETLOCAL
SET SESSIONNUMBER=-1
FOR /F "skip=1 tokens=3" %%i in ('query session %username% ^| find /v ">"') DO SET SESSIONNUMBER=%%i
IF {%SESSIONNUMBER%}=={-1} GOTO :EOF
tscon.exe %SESSIONNUMBER%
ENDLOCAL
logoff.exe