Hi!
When you initialize the service, you have to set the "CanHandleSessionChangeEvent" property to true. It is set to false by default. You also need to enable other service abilities explicitly:
EDIT: Where the service component is initialized:
private void InitializeComponent()
{
this.CanHandleSessionChangeEvent = true;
this.ServiceName = "MyUserMonitoringServiceName";
}
Some other things you can enable here:
this.AutoLog = true;
this.CanHandlePowerEvent = true;
this.CanPauseAndContinue = true;
this.CanShutdown = true;
this.CanStop = true;
EDIT 2:
Instead of the way you process your change event...
void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
once you have enabled the ability as above, create your event handler like this:
protected override void OnSessionChange(SessionChangeDescription changeDescription)
{
switch(changeDescription.Reason)
{
case SessionChangeReason.SessionLock:
LogEntry(string.Format("Locked at {0}", DateTime.Now));
break;
case SessionChangeReason.SessionLogoff:
LogEntry(string.Format("Logged Off at {0}", DateTime.Now));
break;
case SessionChangeReason.SessionLogon:
LogEntry(string.Format("Logged On at {0}", DateTime.Now));
break;
case SessionChangeReason.SessionUnlock:
LogEntry(string.Format("Unlocked at {0}", DateTime.Now));
break;
default:
break;
}
}
Hope that helps!