There is a new example in the JEDI API trunk folder. It’s about Session Notification of Windows Terminal Service. It really easy to understand and use. The main purpose of session notification is to slow down CPU consumption or GUI drawings of applications. If a user locks the computer, she won’t see nice drawings or messageboxes. Also consider a laptop with a batterie only. The user don’t want to see (or not) your application consume a lot of power in the background without her knowledge.

These are the main steps to get session notifications:

  1. Create a WM_WTSSESSION_CHANGE procedure that receives the notifications.
  2. Register to notificiations using WTSRegisterSessionNotification.
  3. Wait for notifications….
  4. Unregister with WTSUnRegisterSessionNotification.

There are lots of notifications:

Message Description
WTS_CONSOLE_CONNECT A new session was connected to the local console.
WTS_CONSOLE_DISCONNECT A session was removed from the local console.
WTS_REMOTE_CONNECT A new session was connected to the remote console.
WTS_REMOTE_DISCONNECT A new session was removed from the remote console.
WTS_SESSION_LOGON A user has logged on to the session.
WTS_SESSION_LOGOFF A user logged off from the session.
WTS_SESSION_LOCK The session is locked.
WTS_SESSION_UNLOCK The session is unlocked.
WTS_SESSION_REMOTE_CONTROL The session changed its remote status.
(remotely or locally controlled)

This technique is only available in Windows XP and newer. It also cannot be used for service applications.

For your convenience there is a direct download here. Latest versions are also available from the JEDI API Subversion repository.