WMI does not work in a logout event of a Windows Service

I made a Windows service to get user information for logging in, logging out, locking and unlocking a computer. I used WMIto get information about the user, for example, name, etc. The service works great when logging in, locking and unlocking, but cannot get the username from WMI in the Logout event.

How can I find the usernamelogout event?

My code is:

switch (changeDescription.Reason)
{
    case SessionChangeReason.SessionLogon:
        string username = Machine.getInstance().getUsername();
        mode = Convert.ToInt32(CommonModule.sessionEvents.Logon);                            
        break;
    case SessionChangeReason.SessionLogoff:
        string username = Machine.getInstance().getUsername();
        mode = Convert.ToInt32(CommonModule.sessionEvents.Logout);                           
        break;
    case SessionChangeReason.SessionLock:
        string username = Machine.getInstance().getUsername();
        mode = Convert.ToInt32(CommonModule.sessionEvents.Lock);                            
        break;
    case SessionChangeReason.SessionUnlock:  
        string username = Machine.getInstance().getUsername();  
        mode = Convert.ToInt32(CommonModule.sessionEvents.UnLock);                            
        break;
    default:                           
        break;
}
+4
source share

Source: https://habr.com/ru/post/1547126/


All Articles