-1

While a user unlocks the windows, the application needs to do some tasks in windows 7. It is a normal application, not a service. I have tried following- How to get windows unlock event in c# windows application?

this solution works in windows 10 but not in windows 7. What can be done?

Nishi
  • 1
  • 2

1 Answers1

-1

See this, windows locking this events you must unlock this in User Configuration > Policies > Administrative Templates > Personalization > Screen saver timeout Or do this:

   //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;
             }

        }

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

Mondonno
  • 161
  • 1
  • 15