As Reed pointed out, you can access the event logs and see when they were created. AFAIK there are no special event records for starting / shutting down the system, but you can look for services that usually start / stop on Windows. Although using this approach means that it will not be 100% accurate, let's say if it crashes or it starts manually / stops / restarts. One of the events that I consider to be the most accurate is the EventLog service start / stop event.
if (EventLog.Exists("System")) { var log = new EventLog("System", Environment.MachineName, "EventLog"); var entries = new EventLogEntry[log.Entries.Count]; log.Entries.CopyTo(entries, 0); var startupTimes = entries.Where(x => x.InstanceId == 2147489653).Select(x => x.TimeGenerated); var shutdownTimes = entries.Where(x => x.InstanceId == 2147489654).Select(x => x.TimeGenerated); }
Edit
Turns out a shutdown event has occurred. You can replace Linq to get it:
var shutdownEvents = entries.Where(x => x.InstanceId == 2147484722);
Matt Sep 13 '11 at 20:22 2011-09-13 20:22
source share