Super User is a question and answer site for computer enthusiasts and power users. 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

I checked this thread, but it did not solve my exact problem.

I need to run a script on when a connection is made across my network using windows remote desktop connection. The thread listed above works for the initial login, however, if I don't log out (which is necessary for some processes running on my network), then it wont run the script again the next time someone connects to the system using remote desktop connection. Previously we were using pcAnywhere to achieve this, however after running into some graphical issues with pcAnywhere, we have decided to move away from it to RDC.

For a little more information, we need to have an email sent out anytime a connection is made to particular machines. The login name will always be the same for those systems and we do not log off when closing the connection.

share|improve this question
up vote 2 down vote accepted

To my knowledge Windows does not provide a built-in method for running a program or script on connection, only log on. You'll need to find a program that registers with Windows (using WTSRegisterSessionNotification) and listens for the WM_WTSSESSION_CHANGE message.

A program that does the above will receive notifications from Windows about user logons, logoffs, connections, disconnections, and all of the events needed to launch a script at connection as well as log on.

Off the top of my head I don't know of any applications (other than pcAnywhere) that can do this.

share|improve this answer
This is just about 100% of what I need. I was able to extend the wrapper in the page you provided quickly to verify it worked for my needs. Now I need to get the name of the connecting machine and its current logged in user. Do you know where to get that information off the top of your head? – Nick Larsen Mar 31 '10 at 18:43
Digging a little deeper, I found there is a wrapper already written for my needs.… – Nick Larsen Mar 31 '10 at 20:58

You can make a new scheduled task and define the trigger to "At the moment of a new connection to a user session"

share|improve this answer
"We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed." – gparyani Feb 3 '14 at 20:02
@gparyani, this is all information I needed. No need for a bunch of screenshots, if you'd ask me. – Arjan Nov 3 '15 at 7:27

If you're familiar with programming in .net, you may want to look at this thread over at Stack Overflow.

According to Steven A. Lowe:


System.Windows.Forms.SystemInformation.TerminalServerSession will be true for a remote desktop session (or VNC session)

You may also be able to monitor for a connection on the RDP, which by default is TCP 3389.

share|improve this answer
While .TerminalServerSession should return true when a connection is established there is no event to fire. Additionally, when a user disconnects and the program is still running it will still return true for being run in a terminal server session and will have no knowledge when the user reconnects. – Joshua Mar 30 '10 at 14:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .