Question

I know this question has been asked before in different situations.

I want to write a C# program that pops up a message when a Windows Vista or Windows 7 computer has fully booted up. (Everything is loaded, the hard drive has settled and the computer is responsive)

Currently I am using a timer. I was wondering if there was maybe a way to determine when all the services have started or something like that?

Edit:

I have something that seems to work fairly well:

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 + "%"; 
    }
}
Était-ce utile?

La solution

You could try for resting CPU usage, hard drive usage, or perhaps a combination of both. My computer is 1 to 4% usage if nothing is going on. During boot it's much higher. Might have to do some kind of math to find trends of spikes and stability. That's how I'd go about it, anyway. I don't know about the services option. I kinda doubt there's a way to ask each one if they're done loading and doing their thing even if you could get a list of them.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top