在哪里可以找到有关处于待机模式的窗口的信息

本文关键字:模式 于待机 窗口 信息 在哪里 | 更新日期: 2023-09-27 18:20:22

我有一个C#应用程序来查找用户的"开始工作"answers"完成工作"事件。目标是获得一个包含日期时间值的列表,当电脑"启动"和再次"关闭"时。

这适用于登录/注销和休眠,但不适用于待机(save energy)。用eventvwr搜索时,我找不到连接到"进入待机状态"answers"从待机状态唤醒"的正确事件。

有了这个,我从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电源疑难解答"answers"Microsoft Windows内核电源"。这些协议似乎指向了正确的方向。。。

在哪里可以找到有关处于待机模式的窗口的信息

并非所有内容都会列在事件日志中,因为它们并不重要,因此(默认情况下)需要写入日志(在磁盘上)。

如果您的应用程序可以在后台运行,那么您可以订阅其中的一些事件并做出相应的反应。正如"C Sharper"已经写的那样,您可以在SystemEvents类中找到它们。

  • 准备就绪(会话结束-在用户试图注销或关闭系统时发生。)
  • 用户锁定屏幕(会话开关-在当前登录的用户发生更改时发生)

如果这是一个windows窗体应用程序,则可以使用SystemEvents类。

using System;
using Microsoft.Win32;
public sealed class App 
{
    static void Main() 
    {         
        // Set the SystemEvents class to receive event notification when a user 
        // preference changes, the palette changes, or when display settings change.
        SystemEvents.SessionEnding+= SystemEvents_SessionEnding;
        Console.WriteLine("This application is waiting for system events.");
        Console.WriteLine("Press <Enter> to terminate this application.");
        Console.ReadLine();
    }
    // This method is called when a user preference changes.
    static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e) 
    {
       e.Category);
    }
}