Not able to detect windows logon
I have a windows service code which detects logoff and logon. the service detects logoff but its not detecting logon.
public ServiceLogoff()
{ this.CanHandleSessionChangeEvent = true; 开发者_StackOverflow中文版
}
protected override void OnSessionChange(SessionChangeDescription changeDescription)
{
if (changeDescription.Reason == SessionChangeReason.SessionLogoff)
{
tw.WriteLine("logoff detected" + DateTime.Now);
}
else if(changeDescription.Reason == SessionChangeReason.SessionLogon)
{
tw.WriteLine("logon detected" + DateTime.Now);
}
精彩评论