To the main page...The list of my products...Some texts...Sample applications, tips, tricks...If you need support...

Advanced interactive service
Step 5. Logon and logoff detection.

It sounds strange but Windows API does not have any function, hook or global variable that would indicate the presence of interactive user. MS documentation recommends to monitor the list of processes1 and search for process that is specified in the Shell registry key. If this process runs then it is supposed that interactive user is logged on. If such process doesn`t run then it is assumed that there is no interactive user currently logged on. The SvCom TsvLogonSensor component uses this idea to generate events when the interactive user logs on or off. We shall use the OnLogon event to reactivate tray icon.

Add the TsvLogonSensor component to the form

Logon sensor screenshot

and set its OnLogon event handler:


procedure TServiceMainForm.LogonSensorLogon(Sender: TObject);
    if Visible then exit; // Tray icon is not necessary now

The resulting code can be downloaded here (zip, 3.5kb). Test it and ensure that tray icon successfully restores when the logoff/logon occurs.

Well, this step finalizes this example. All conclusions are summarized here. Your comments are welcome.

1. And methods that get the list of processes essentially differ for NT/2000 and 95/98! The PSAPI dll should be used for NT while system snapshots are used in 95/98. By the way, SvCom 4.0 includes GetProcessList method that works in both systems. It`s usage was shown in previous example.

<< | Index | Step 1 | Step 2 | Step 3 | Step 4 | Step 5 | Conclusions | >>
Add your comment | Read comments

© 1998-2001 Alexey Dynnikov
My ICQ # is 18267212