1 PerformanceCounter pc = new PerformanceCounter("System", "System Up Time");
2
3 //Normally starts with zero. do Next Value always.
4 pc.NextValue();
5
6 TimeSpan ts = TimeSpan.FromSeconds(pc.NextValue());
7
8 MessageBox.Show(Environment.MachineName +
9 " has been up for \n\n" +
10 (ts.Days < 1 ? "" : ts.Days + " days, ") +
11 (ts.Hours < 1 ? "" : ts.Hours + " hours, ") +
12 (ts.Minutes < 1 ? "" : ts.Minutes + " minutes ") +
13 " and " + ts.Seconds + " seconds.");
Nice, neat and simple. Get a compiled executable here
Comments