Skip to content

Instantly share code, notes, and snippets.

@pontusm
Created February 25, 2012 07:51
Show Gist options
  • Save pontusm/1907277 to your computer and use it in GitHub Desktop.
Save pontusm/1907277 to your computer and use it in GitHub Desktop.
Retrieve computer uptime
public static TimeSpan GetUptime()
{
ManagementObject mo = new ManagementObject(@"\\.\root\cimv2:Win32_OperatingSystem=@");
DateTime lastBootUp = ManagementDateTimeConverter.ToDateTime(mo["LastBootUpTime"].ToString());
return DateTime.Now.ToUniversalTime() - lastBootUp.ToUniversalTime();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment