确定Windows计算机何时完全启动并变为响应

时间:2014-02-17 01:13:52

标签: c# windows boot

我知道之前在不同情况下已经提出过这个问题。

我想写一个C#程序,当Windows Vista或Windows 7计算机完全启动时弹出一条消息。 (一切都已加载,硬盘已稳定,计算机响应)

目前我正在使用计时器。我想知道是否有办法确定所有服务何时开始或类似的东西?

编辑:

我有一些似乎运作良好的东西:

using System.Diagnostics;
public partial class Form1 : Form
{
    private PerformanceCounter cpuCounter;
    private PerformanceCounter diskCounter;
    private int seconds;
    private int lowUsage;

    private const String timeMsg = "Waiting for Boot: ";
    private const String cpuMsg = "CPU: ";
    private const String diskMsg = "Disk: ";

    public Form1()
    {
        InitializeComponent();

        cpuCounter = new PerformanceCounter();
        cpuCounter.CategoryName = "Processor";
        cpuCounter.CounterName = "% Processor Time";
        cpuCounter.InstanceName = "_Total";

        diskCounter = new PerformanceCounter();
        diskCounter.CategoryName = "PhysicalDisk";
        diskCounter.CounterName = "% Disk Time";
        diskCounter.InstanceName = "_Total";

        seconds = 0;
        lowUsage = 0;

        Timer timer = new Timer();
        timer.Interval = 1000;
        timer.Tick += tick;
        timer.Start();

        timeLabel.Text = timeMsg + seconds;
        cpuLabel.Text = cpuMsg + "100%";
        diskLabel.Text = diskMsg + "100%";

        StartPosition = FormStartPosition.CenterScreen;

    }

    private void tick(Object o, EventArgs e)
    {
        seconds++;
        int cpu = (int)cpuCounter.NextValue();
        int disk = (int)diskCounter.NextValue();

        if (cpu < 5 && disk < 5) lowUsage++;
        else lowUsage = 0;

        if (lowUsage >= 5 && seconds > 35) Application.Exit();

        timeLabel.Text = timeMsg + seconds;
        cpuLabel.Text = cpuMsg + cpu + "%";
        diskLabel.Text = diskMsg + disk + "%"; 
    }
}

1 个答案:

答案 0 :(得分:2)

您可以尝试休息CPU使用率,硬盘驱动器使用情况,或者两者兼而有之。如果没有任何操作,我的电脑使用率为1%到4%。在启动过程中,它要高得多。可能需要做一些数学计算才能找到尖峰和稳定性的趋势。无论如何,我就是这样做的。我不知道服务选项。我有点怀疑有一种方法可以询问每个人是否已完成加载和做他们的事情,即使你能得到他们的清单。