locked
Capturing System Event RRS feed

  • Question

  • User1224235962 posted

    Hi All,

    I am trying this code in services but it is giving an error "changeDescription not declared "

    plese suggest

    protected override void OnSessionChange(SessionChangeDescription changeDescription)  
    {  
    switch (changeDescription.Reason)  
                {  
                    case SessionChangeReason.SessionLogon:  
                        //Logon  
                        break;  
                    case SessionChangeReason.SessionLogoff:  
                        //Logoff  
                        break;  
                    case SessionChangeReason.RemoteConnect:  
                        //Remote Connect  
                        break;  
                    case SessionChangeReason.RemoteDisconnect:  
                        //Remote Disconnect  
                        break;  
                    case SessionChangeReason.SessionLock:  
                        //lock  
                        break;  
                    case SessionChangeReason.SessionUnlock:  
                        //Unlock  
                        break;  
                    default:  
                        break;  
                }  
    }  



     

    Thursday, July 5, 2012 4:13 AM

Answers

  • User2036813175 posted
    class MyService : ServiceBase
        {
            public MyService()
            {
                this.CanHandleSessionChangeEvent = true;
            }
    
            protected override void OnSessionChange(SessionChangeDescription changeDescription)
            {
                switch (changeDescription.Reason)
                {
                    case SessionChangeReason.SessionLogon:
                        Debug.WriteLine(changeDescription.SessionId + " logon");
                        break;
                    case SessionChangeReason.SessionLogoff:
                        Debug.WriteLine(changeDescription.SessionId + " logoff");
                        break;
                    case SessionChangeReason.SessionLock:
                        Debug.WriteLine(changeDescription.SessionId + " lock");
                        break;
                    case SessionChangeReason.SessionUnlock:
                        Debug.WriteLine(changeDescription.SessionId + " unlock");
                        break;
                }
    
                base.OnSessionChange(changeDescription);
            }
        }
    

    i hope this will solve your problem

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 5, 2012 11:44 AM