Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Every one,

I have developed a windows application in which i am capturing the windows events like lock,unlock, logon,disconnect etc.

I have written the following code in windows service for capturing the events as they occured.

protected override void OnSessionChange(SessionChangeDescription changeDescription)
       {
           string pcName = Environment.MachineName.ToUpper();
          System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
               System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = "MMM dd yyyy";
               System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern = "hh:mm:ss tt";
               System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.DateSeparator = "/";
               switch (changeDescription.Reason)
               {

                   case SessionChangeReason.SessionLock:
                       Idlog("4800");
                       Eventlogs(pcName, "4800", "System locked", DateTime.Now);
                       break;
                   case SessionChangeReason.SessionLogoff:
                       Eventlogs(pcName, "4647", "System logoff", DateTime.Now);
                       break;
                   case SessionChangeReason.SessionLogon:
                       Idlog("4624");
                       Eventlogs(pcName, "4624", "System logon", DateTime.Now);
                       break;
                   case SessionChangeReason.SessionUnlock:
                       Idlog("4801");
                       Eventlogs(pcName, "4801", "System Unlocked", DateTime.Now);
                       break;
                   case SessionChangeReason.RemoteDisconnect:
                       Eventlogs(pcName, "4779", "Session disconnected", DateTime.Now);
                       break;
                   case SessionChangeReason.RemoteConnect:
                       //LogEntry("Remote connect at {0}=" + DateTime.Now.AddMilliseconds(DateTime.Now.Millisecond));
                       Idlog("4778");
                       Eventlogs(pcName, "4778", "Session reconnected", DateTime.Now);
                       break;
                   case SessionChangeReason.ConsoleConnect:
                       // LogEntry("console connect at {0}=" + DateTime.Now.AddMilliseconds(DateTime.Now.Millisecond));
                       Idlog("4778");
                       Eventlogs(pcName, "4778", "Session c reconnected", DateTime.Now);
                       break;
                   case SessionChangeReason.ConsoleDisconnect:
                       //LogEntry("console disconnect at {0}=" + DateTime.Now.AddMilliseconds(DateTime.Now.Millisecond));
                       Eventlogs(pcName, "4779", "Session c disconnecetd", DateTime.Now);
                       break;
                   default:
                       break;

               }
           //}
       }


Quote:
Everything is working fine but the

SessionChangeReason.RemoteConnect and SessionChangeReason.RemoteDisconnect are being fired two times always when i perform Disconnect and Reconnect

and the order is as follows


Message
Session disconnected
Session reconnected
Session disconnected
Session reconnected
So for two events iam getting four results.

Can anybody please help me why this is happening?

Thanks in Advance


What I have tried:

Unable to find the root cause of this Event
Posted
Comments
satti_ananthreddy 16-Sep-16 4:20am    
can any body please help to my question its very urgent

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900