繁体   English   中英

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

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

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

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

如果您的应用程序可以在后台运行,您可以订阅其中一些事件并做出相应的反应。 正如“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);
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM