PerformanceCounter pc = new PerformanceCounter(“System”,
“System Up Time”);
//Normally starts with zero. do Next Value always.
pc.NextValue();
TimeSpan ts = TimeSpan.FromSeconds(pc.NextValue());
MessageBox.Show(Environment.MachineName +
” has been up for \n\n” +
(ts.Days < 1 ? “” : ts.Days + ” days, “) +
(ts.Hours < 1 ? “” : ts.Hours + ” hours, “) +
(ts.Minutes < 1 ? “” : ts.Minutes + ” minutes “) +
” and “ + ts.Seconds + ” seconds.”);
Nice, neat and simple.
Get a compiled executable here
This entry (Permalink) was posted on Thursday, December 7th, 2006 at 11:36 am and is filed under .Net Framework, C#, Downloadable. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response , or trackback from your own site.