Beispiel #1
0
        /// <summary>
        /// 当前登录的用户变化(登录、注销和解锁屏)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
        {
            switch (e.Reason)
            {
            case Microsoft.Win32.SessionSwitchReason.SessionLogon:    //用户登录
            case Microsoft.Win32.SessionSwitchReason.SessionUnlock:   //解锁屏
                InitTimers_Screen();
                //InitTimers_Wallpaper();
                break;

            case Microsoft.Win32.SessionSwitchReason.SessionLock:    //锁屏
            case Microsoft.Win32.SessionSwitchReason.SessionLogoff:  //注销
                timerS.Stop();
                //timerW.Stop();
                if (screensaver != null && screensaver.Visibility == Visibility.Visible)
                {
                    screensaver.Close();
                }
                // 遍历所有子窗体,如果找到屏保窗体,则关闭(作废原因:上面代码可以替代)
                //foreach (Window window in Application.Current.Windows)
                //{
                //    if (window.Title == "Screensaver")
                //    {
                //        Screensaver frm = window as Screensaver;
                //        frm.Close();
                //        return;
                //    }
                //}
                break;
            }
        }
Beispiel #2
0
        private void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
        {
            string guid = null;

            if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock)
            {
                // Locked
                Console.WriteLine("Workstation locked");
                guid = Properties.Settings.Default.LockPlan;
            }
            else if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock)
            {
                // Unlocked
                Console.WriteLine("Workstation unlocked");
                guid = Properties.Settings.Default.UnlockPlan;
            }

            if (guid != null && powerPlans.ActivePlan.Guid != guid)
            {
                PowerPlan plan = powerPlans.Plans.Find(p => p.Guid == guid);
                if (plan != null)
                {
                    powerPlans.SetActivePlan(plan);
                }
            }
        }
Beispiel #3
0
 private void System_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock)
     {
         this.Timer.Stop(); this.Timer.Start(); this.Timer_Tick(sender, e);
     }
 }
Beispiel #4
0
 void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock)
     {
         this.Hide();
     }
 }
Beispiel #5
0
 static void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     if (Utils.LoggingUtils.DefaultLogger != null)
     {
         Utils.LoggingUtils.DefaultLogger.AddLogMessage("LogonTracer", MessageType.Info, "Session switch, reason = {0}", e.Reason);
     }
 }
Beispiel #6
0
        void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
        {
            if (e.Reason != Microsoft.Win32.SessionSwitchReason.SessionUnlock)
            {
                return;
            }

            // Another session already running
            if (this.IsRunning)
            {
                return;
            }

            // No work reports created
            if (this.workReports.Count == 0)
            {
                return;
            }

            // No work reports from today
            if (this.workReports[this.workReports.Count - 1].FromTime.DayOfYear != DateTime.Now.DayOfYear)
            {
                return;
            }

            // Continue counting
            this.StartCounting(StartCountingReasons.SystemUnlocked, DateTime.Now);
        }
Beispiel #7
0
 void SessionSwitched(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock)
     {
         if (Control.IsKeyLocked(Keys.CapsLock))
         {
             keybd_event(0x14, 0x45, 0x1, (UIntPtr)0);
             keybd_event(0x14, 0x45, 0x1 | 0x2, (UIntPtr)0);
         }
     }
 }
 // pause/resume preview on lock/unlock windows session
 private void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock)
     {
         _preview.Resume();
     }
     else if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock)
     {
         _preview.Pause();
     }
 }
Beispiel #9
0
 // PC Locked
 private void SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock || e.Reason == Microsoft.Win32.SessionSwitchReason.RemoteDisconnect)
     {
         machineLockedTime = DateTime.Now;
     }
     else if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock || e.Reason == Microsoft.Win32.SessionSwitchReason.RemoteConnect)
     {
         machineLockedTime = null;
     }
 }
Beispiel #10
0
 // PC Locked
 private void SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock || e.Reason == Microsoft.Win32.SessionSwitchReason.RemoteDisconnect)
     {
         isActive = false;
     }
     else if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock || e.Reason == Microsoft.Win32.SessionSwitchReason.RemoteConnect)
     {
         isActive = true;
     }
 }
 protected void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock)
     {
         OnSessionLock();
     }
     if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock)
     {
         OnSessionUnlock();
     }
 }
Beispiel #12
0
 private void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock)
     {
         isLocked = LockScreenStatus.Locked;
     }
     else if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock)
     {
         isLocked = LockScreenStatus.Unlocked;
     }
 }
Beispiel #13
0
 private void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock)
     {
         InitStartTime();
         timer.Start();
     }
     else if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock)
     {
         timer.Stop();
     }
 }
Beispiel #14
0
        /// <summary>
        /// Saves Sessionstate on change
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveCurrentSessionState(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
        {
#if TRACE
            INFO($"SaveCurrentSessionState is {e.Reason}");
#endif
            switch (e.Reason)
            {
            case Microsoft.Win32.SessionSwitchReason.SessionLock: DeviceLocked = true; break;

            case Microsoft.Win32.SessionSwitchReason.SessionUnlock: DeviceLocked = false; break;
            }
        }
Beispiel #15
0
 static void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     switch (e.Reason)
     {
         /*case Microsoft.Win32.SessionSwitchReason.RemoteConnect:
          *  _logonTracerWorker.RegisterSession();
          *  break;
          * case Microsoft.Win32.SessionSwitchReason.SessionLogon:
          *  _logonTracerWorker.RegisterSession();
          *  break;*/
     }
 }
        private void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
        {
            switch (e.Reason)
            {
            case Microsoft.Win32.SessionSwitchReason.SessionLock:
                SessionLock?.Invoke(this, EventArgs.Empty);
                break;

            case Microsoft.Win32.SessionSwitchReason.SessionUnlock:
                SessionUnlock?.Invoke(this, EventArgs.Empty);
                break;
            }
        }
Beispiel #17
0
 void SystemEvents_DisplaySwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock && lockedDisplay == false)
     {
         lockedDisplay = true;
         Log("DisplayLocked - " + (Locked ? "Locked" : "Unlocked"));
     }
     else if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock && lockedDisplay == true)
     {
         lockedDisplay = false;
         Log("DisplayUnlocked - " + (Locked ? "Locked" : "Unlocked"));
     }
 }
Beispiel #18
0
        void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
        {
            switch (e.Reason)
            {
            case Microsoft.Win32.SessionSwitchReason.SessionLock:
                addTransaction(new string[] { "BREAK", "Computer locked" });
                break;

            case Microsoft.Win32.SessionSwitchReason.SessionUnlock:
                addTransaction(mGridData.Item(mGridData.Count - 2).ToArray());
                break;
            }
        }
Beispiel #19
0
        void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
        {
            switch (e.Reason)
            {
            case Microsoft.Win32.SessionSwitchReason.ConsoleDisconnect:
                userSwitchOff();
                break;

            case Microsoft.Win32.SessionSwitchReason.ConsoleConnect:
                userSwitchOn();
                DoRegistered();
                break;
            }
        }
Beispiel #20
0
 void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     /*
      *     ConsoleConnect = 1,
      *     ConsoleDisconnect = 2,
      *     RemoteConnect = 3,
      *     RemoteDisconnect = 4,
      *     SessionLogon = 5,
      *     SessionLogoff = 6,
      *     SessionLock = 7,
      *     SessionUnlock = 8,
      *     SessionRemoteControl = 9,
      */
     SessionSwitch(e.Reason.ToString());
 }
 private void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock ||
         e.Reason == Microsoft.Win32.SessionSwitchReason.RemoteDisconnect)
     {
         Stop();
         CommandManager.InvalidateRequerySuggested();
     }
     else if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock ||
              e.Reason == Microsoft.Win32.SessionSwitchReason.RemoteConnect)
     {
         Start();
         CommandManager.InvalidateRequerySuggested();
     }
 }
Beispiel #22
0
 void SessionSwitchHandler(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock)
     {
         tmrMain.Stop();
         tmrUpdateStatus.Stop();
     }
     else if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock)
     {
         if (tbxStatus.Text != "Stopped")
         {
             frm_Restart();
         }
         // else preserve paused state
     }
 }
Beispiel #23
0
        private void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
        {
            if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock)
            {
                var mainWindow = GetMainWindow();
                mainWindow.OnSessionUnlock();

                if (!IsSuspended)
                {
                    InitStartTime();
                }

                timer.Start();
            }
            else if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock)
            {
                timer.Stop();
            }
        }
Beispiel #24
0
 void OnSystemEventsSessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock)
     {
         stationLocked = true;
         //I left my desk
         logger.Info("Session Locked");
         lastLockTime = DateTime.Now;
     }
     else if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock)
     {
         stationLocked = false;
         //I returned to my desk
         logger.Info("Session Unlocked");
         if (usageStat.State == "LOCK" && ((TimeSpan)(DateTime.Now - lastLockTime)).TotalMinutes > AppConfig.breakTime)
         {
             logger.Info("Lock Period Ended");
             usageStat.RestartSession();
             saveStat();
         }
     }
 }
        private void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
        {
            if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock)
            {
                var timeSinceLastCheck = DateTime.Now.Subtract(_lastCheck).TotalMinutes;

                if (timeSinceLastCheck >= TimerIntervalMinutes)
                {
                    if (timeSinceLastCheck >= STALE_INTERVAL_MIN)
                    {
                        // on unlock when refreshing we explicitly want the user to see that we are refreshing
                        // but only if we believe that the data is way out of date
                        App.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            App.TrayIcon.DataContext = ChimeHelperTray.MEETINGS_LOADING;
                        }));
                    }

                    CheckForChimeMeetingsAsync();
                }
            }
        }
Beispiel #26
0
        private async void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
        {
            switch (e.Reason)
            {
            case Microsoft.Win32.SessionSwitchReason.ConsoleConnect:
                break;

            case Microsoft.Win32.SessionSwitchReason.ConsoleDisconnect:
                break;

            case Microsoft.Win32.SessionSwitchReason.RemoteConnect:
                break;

            case Microsoft.Win32.SessionSwitchReason.RemoteDisconnect:
                break;

            case Microsoft.Win32.SessionSwitchReason.SessionLogon:
                break;

            case Microsoft.Win32.SessionSwitchReason.SessionLogoff:
                break;

            case Microsoft.Win32.SessionSwitchReason.SessionLock:
                break;

            case Microsoft.Win32.SessionSwitchReason.SessionUnlock:
                await cameraController.StartPreviewAsync();

                preview.Source = cameraController.GetCapturePreview();
                break;

            case Microsoft.Win32.SessionSwitchReason.SessionRemoteControl:
                break;

            default:
                break;
            }
        }
Beispiel #27
0
 private void SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock)
     {
         if (isTrackingEnabled == false)
         {
             return;
         }
         usageProcessor.NewUsage(UsageTypes.Locked);
         usageProcessor.UsageEnded(UsageTypes.Idle);
         mediator.NotifyColleagues(MediatorMessages.STOP_TRACKING);
         isTrackingEnabled = false;
     }
     else if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock)
     {
         if (settings.EnableIdle && settings.TrackingEnabled)
         {
             isTrackingEnabled = true;
         }
         usageProcessor.UsageEnded(UsageTypes.Locked);
         mediator.NotifyColleagues(MediatorMessages.RESUME_TRACKING);
     }
 }
Beispiel #28
0
 void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock)
     {
         SessionActive = true;
         Logging.OnLogMessage("The PC has been unlocked", MessageType.Info);
     }
     else if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock)
     {
         SessionActive = false;
         Logging.OnLogMessage("The PC has been locked", MessageType.Info);
     }
     else if (e.Reason == Microsoft.Win32.SessionSwitchReason.RemoteDisconnect)
     {
         SessionActive = false;
         Logging.OnLogMessage("A remote connection has been terminated", MessageType.Info);
     }
     else if (e.Reason == Microsoft.Win32.SessionSwitchReason.RemoteConnect)
     {
         SessionActive = true;
         Logging.OnLogMessage("A remote connection has been initiated", MessageType.Info);
     }
 }
        private IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (OnSessionSwitch == null)
            {
                return(IntPtr.Zero);
            }

            // handler of console display state system event
            if (msg == WM_POWERBROADCAST)
            {
                if (wParam.ToInt32() == PBT_POWERSETTINGCHANGE)
                {
                    var s = (POWERBROADCAST_SETTING)Marshal.PtrToStructure(lParam, typeof(POWERBROADCAST_SETTING));
                    if (s.PowerSetting == GUID_CONSOLE_DISPLAY_STATE)
                    {
                        Microsoft.Win32.SessionSwitchReason reason = new Microsoft.Win32.SessionSwitchReason();

                        switch (s.Data)
                        {
                        case (0x0):
                            reason = Microsoft.Win32.SessionSwitchReason.SessionLock;
                            break;

                        case (0x1):
                        case (0x2):
                            reason = Microsoft.Win32.SessionSwitchReason.SessionUnlock;
                            break;
                        }

                        Microsoft.Win32.SessionSwitchEventArgs args = new Microsoft.Win32.SessionSwitchEventArgs(reason);
                        OnSessionSwitch(this, args);
                    }
                }
            }

            return(IntPtr.Zero);
        }
Beispiel #30
0
 void OnIn(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
 {
     controller.OnIn();
 }