Esempio n. 1
0
        void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
        {
            string currentUserName = cWindowsIdentity.GetCurrentLoginUserName();

            List <string> lstring = new List <string>();

            if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock || e.Reason == Microsoft.Win32.SessionSwitchReason.ConsoleDisconnect)
            { // lock
                mWindowsState = sWindowsState.SessionLock;
                lstring.Add(currentUserName + " lock");
            }
            if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock || e.Reason == Microsoft.Win32.SessionSwitchReason.ConsoleConnect)
            { // unlock
                mWindowsState = sWindowsState.SessionUnLock;
                lstring.Add(currentUserName + " unlock");
            }
            if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLogoff)
            {  // logoff
                mWindowsState = sWindowsState.SessionLogoff;
                lstring.Add(currentUserName + " logOff");
            }
            if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLogon)
            {  // login
                mWindowsState = sWindowsState.SessionLogon;
                lstring.Add(currentUserName + " logIn");
            }
            ExportImportFile.StringArrayToFile(lstring, "log.txt", true);
        }
Esempio n. 2
0
 public cWindowsIdentity()
 {
     Microsoft.Win32.SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
     mWindowsState = sWindowsState.SessionUnknow;
 }