I connect to my PC (Windows XP Pro, which runs 24/7) through RDP on an off through the day.
I have a background process that should do some things upon RDP connection, but I couldn’t figure a way to make it detect the establishing of the RDP connection.
No new processes are created, WTSQuerySessionInformation doesn’t help (I connect to the same eternal Windows session).
The answer is
WTSRegisterSessionNotification()from wtsapi32.dll.This signs you up for receiving
WM_WTSSESSION_CHANGEnotifications, whoseWParamcould beWTS_REMOTE_CONNECT,WTS_REMOTE_DISCONNECT. That does it.Here is the simplest AutoIt implementation: