Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


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

share|improve this question
up vote 3 down vote accepted

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

FOR /F "skip=1 tokens=3" %%i in ('query session %username% ^| find /v ">"') DO SET SESSIONNUMBER=%%i
share|improve this answer
Even if this doesn't do what the OP wants I think there is lots of win in looking at an approach like this. – Evan Anderson Mar 6 '13 at 14:52
Actually this seems better, if I understand properly what it does. I will try this out. – Jeremy Holovacs Mar 6 '13 at 16:36

Create a Group Policy (domain or edit the local computer settings): Computer Configuration, Administrative Templates, Windows Components, Terminal Services, Restrict Terminal Services users to a single remote session setting, Enable.

This would force the user to the existing session; unless someone else is currently in the session (where is gets slightly more complicated, but you don't seem concerned about the possibility of two people connecting at the same time).

This isn't what you asked for, but prevents the problem instead of adding some crazy script.

share|improve this answer
What sort of effect will this have? Will it prevent login, or force the user to the active connection? Having the login prevented would be undesirable; as I said, the system is fragile and we often need to login and fix things. – Jeremy Holovacs Mar 6 '13 at 16:37
updated my answer – Chris S Mar 6 '13 at 17:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.