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

Where can I find information about windows was in standby-mode

我有一个 C# 应用程序来查找用户的 "start working" 和 "finish working" 事件。目标是获得一个包含日期时间值的列表,当 PC 为 "up" 和再次为 "down" 时。

这适用于 logon/logoff 和休眠,但不适用于待机 (save energy)。使用 eventvwr 搜索我找不到与 "enter standby" 和 "wake up from standby" 相关的正确事件。

有了这个,我从 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"。这些协议似乎指向了正确的方向...

如果这是一个 windows 表单应用程序,您可以使用 SystemEvents class.

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

}

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

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

中找到它们
  • 待命(Session ending - 当用户试图注销或关闭系统时发生。)
  • 用户锁定屏幕(Session switch - 当前登录用户已更改时发生)