Thanks to Joe Sova.
Joe wrote this example because he had an application that played a sound as an alarm. If the user performed a Windows XP fast user switch, logging out and logging in as another user, the application still played the sound even though the user that started the program was not logged in.
This example subclasses to watch for messages indicating a user switch. When it receives those messages, the lParam parameter gives the (user) session ID. See the code for the details.
See also Microsoft the Microsoft article How to write an application that supports the Fast User Switching feature by using Visual Basic .NET in Windows XP.