[英]Determine When Windows Computer has fully booted and becomes responsive
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. 我想编写一个C#程序,当Windows Vista或Windows 7计算机完全启动时弹出一个消息。 (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 + "%";
}
}
You could try for resting CPU usage, hard drive usage, or perhaps a combination of both. 您可以尝试降低CPU使用率,硬盘驱动器使用率,或者两者结合。 My computer is 1 to 4% usage if nothing is going on.
如果没有任何反应,我的计算机的使用率为1-4%。 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.
我有点怀疑是否有一种方法可以询问每个人,即使您可以获得它们的列表,它们是否都已完成加载并完成了他们的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.