我有一个 C# 应用程序来查找用户的“开始工作”和“完成工作”事件。目标是获取包含日期时间值的列表,PC 何时“启动”以及何时再次“关闭”。
这适用于登录/注销和休眠,但不适用于待机 ( save energy
)。搜索eventvwr
我找不到连接到“进入待机”和“从待机中唤醒”的正确事件。
有了这个,我从 Windows 事件日志中读取:
public SortedDictionary<string, UserProfileEvent> ReadUserProfileEvents() {
string queryString = string.Format("*[System[TimeCreated[@SystemTime>='{0}' and @SystemTime<='{1}']]]", this.StartDate.ToString("s"), this.EndDate.ToString("s"));
var q = new EventLogQuery("Microsoft-Windows-User Profile Service/Operational", PathType.LogName, queryString);
var r = new EventLogReader(q);
var liste = new SortedDictionary<string, UserProfileEvent>();
EventRecord e = r.ReadEvent();
UserProfileEvent upe = null;
while (e != null) {
upe = new UserProfileEvent(e);
try {
liste.Add(upe.SortKey, upe);
}
catch (Exception exp) {
throw new Exception("Some error text", exp);
}
e = r.ReadEvent();
}
return liste;
}
任何想法在哪里可以找到正确的事件?
编辑:我刚刚找到“Microsoft-Windows-Power-Troubleshooter”和“Microsoft-Windows-Kernel-Power”。这些协议似乎指向了正确的方向......