【问题标题】:While a user unlocks the windows, the application needs to do some tasks in windows 7当用户解锁 Windows 时,应用程序需要在 Windows 7 中执行一些任务
【发布时间】:2020-09-01 19:39:25
【问题描述】:

当用户解锁 Windows 时,该应用程序需要在 Windows 7 中执行一些任务。它是一个普通应用程序,而不是一个服务。 我试过以下 - How to get windows unlock event in c# windows application?

此解决方案适用于 Windows 10,但不适用于 Windows 7。可以做什么?

【问题讨论】:

    标签: c#


    【解决方案1】:

    看到这个,windows 锁定这个事件你必须解锁这个 User Configuration > Policies > Administrative Templates > Personalization > Screen saver timeout 或者这样做:

       //Define strings for searching the eventlog.
        string lockEvent = "4800";
        string unlockEvent = "4801";
    
         //Define the Eventlog source you want (in this case it's Security)
        string LogSource = @"Security";
    
        //Add these together to make the full query for Lock and Unlock
        string LockQuery = " *[System/EventID=" + lockEvent + "]";
        string UnlockQuery = "*[System/EventID=" + unlockEvent + "]";
    
    
    //Return true if there is any locked events found.
    
        private bool CheckForLock()
        {
            //Create Eventlog Reader and Query
            var elQuery = new EventLogQuery(LogSource, PathType.LogName, LockQuery);
            var elReader = new System.Diagnostics.Eventing.Reader.EventLogReader(elQuery);
    
            //Create a list of Eventlog records and add the found records to this
            List<EventRecord> eventList = new List<EventRecord>();
                    for (EventRecord eventInstance = elReader.ReadEvent();
                        null != eventInstance; eventInstance = elReader.ReadEvent())
                    {
    
                       eventlist.add(eventInstance);
    
                     }
    
              if(eventList.count > 0)
                  {
                      return true;
                  }
               else
                 { 
                     return false;
                 }
    
            }
    

    来自C# SessionSwitchReason.SessionLock NOT triggering when machine is locked via Group Policy

    【讨论】:

      猜你喜欢
      • 2021-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-05
      • 1970-01-01
      • 2011-08-21
      • 2013-08-22
      相关资源
      最近更新 更多