c# - 当用户解锁 Windows 时,应用程序需要在 Windows 7 中执行一些任务
问题描述
当用户解锁 Windows 时,该应用程序需要在 Windows 7 中执行一些任务。它是一个普通的应用程序,而不是一个服务。我尝试过以下 操作-如何在 c# windows 应用程序中获取 windows 解锁事件?
此解决方案适用于 Windows 10,但不适用于 Windows 7。可以做什么?
解决方案
看到这个,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;
}
}
推荐阅读
- javascript - 对并发调用返回 false 的简单锁 - javascript
- java - 执行期间计数器重置
- node.js - Ggraphicsmagick 破坏了 mongoDB。我不知道为什么
- reactjs - 使用 Typescript 反应 Redux,ActionType 的 Reducer 中的属性不可用
- ocaml - 如何在 OCaml 中编写一个接受整数列表并返回具有最大绝对值的元素的函数
- reactjs - 在没有DOM选择器的情况下用鼠标滚轮水平滚动表格?
- android - 如何使用约束布局实现垂直链接
- python - OpenCV中的随机轮廓
- swift - SwiftUI zIndex 里面的列表
- java - 尝试使用 maven 运行 java 项目时出现 ClassNotFoundException 错误