![]() ![]() Took 84 ms using COM, 202ms using wmic command line.Using WMI query of the LastBootUpTime field of Win32_OperatingSystem XP's 32-bit counter rolls over at ~49 days and can't be used for this approach, if your application/library must support older Windows versions Returned values are all within 1/64 of a second of each other. Does not produce a unique/consistent value at the 100-ns resolution of its arguments, as it is dependent on clock ticks.The fastest method, clocking in at 0.112 ms.Using GetTickCount64 and subtracting from current time ![]() I also implemented each of the other 3 answers and have some observations that may help those trying to choose a method. This returns an uptime of 427.0152 seconds. You can use the PerfFormattedData equivalent to get a floating point number of seconds, or read that from the command line in wmic or query the counter in PowerShell: Get-Counter -Counter '\system\system up time' That query produces 132558992761256000 for me, corresponding to Saturday, Janu6:14:36 PM UTC. (Read programmatically using COM, or grab the command line from wmic:) wmic path Win32_PerfRawData_PerfOS_System get systemuptime ![]() You can also see the value the counter returns by reading the WMI table exposing the raw values used to compute this. Reading the counter returns a 64-bit FILETIME value, the number of 100-NS ticks since the Windows Epoch ( 00:00:00 UTC). It is, however, not robust to sleep/hibernate cycles so is probably not much better than GetTickCount()/ GetTickCount64(). It's available programmatically using the PDH Helper methods. The "System Up Time" performance counter on the "System" object is another source. ![]()
0 Comments
Leave a Reply. |