Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

3 Answers

up vote 1 down vote accepted
+150

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? –  NickLarsen Mar 31 '10 at 18:43
    
Digging a little deeper, I found there is a wrapper already written for my needs. msdn.microsoft.com/en-us/library/… –  NickLarsen Mar 31 '10 at 20:58
add comment

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." –  damryfbfnetsi Feb 3 at 20:02
add comment

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:

allegedly,

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
1  
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
add comment

Your Answer

 
discard

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.