Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • Thanks for comparing the solutions, please mention compatibility. Which of those solutions will work on non-win platforms? Commented May 29, 2017 at 19:58
  • 1
    ManagementObject code using "\\.\root\cimv2:Win32_OperatingSystem=@" doesn't work on Windows XP because apparently Win32_OperatingSystem is not a singleton on XP. Instead I found that I needed to use a query to find the primary instance and loop over the query results, as demonstrated in this answer which worked for me on both XP and Win 7: stackoverflow.com/a/7407346/382885 Commented Jul 6, 2017 at 11:54
  • Great answer. Thanks ! I just wanted to add two things : GetTickCount64() is not supported on versions of Windows before Vista, and PerformanceCounter("System", "System Up Time") takes REALLY long on my W7 laptop (more than one minute. Don't ask why.)
    – AFract
    Commented Jul 26, 2017 at 12:52
  • If you use @"dd\ \d\a\y\s\,\ hh\ \h\o\u\r\s\,\ mm\ \m\i\n\u\t\e\s\,\ ss\ \s\e\c\o\n\d\s", it spaces things out nicely. "26 days, 05 hours, 32 minutes, 48 seconds"
    – B E
    Commented Feb 20, 2023 at 20:35