uptime for Win XP?

Tim Golden tim.golden at viacom-outdoor.co.uk
Mon Dec 13 10:29:32 EST 2004


[Peter Hansen]
| 
| Richie Hindle wrote:
| > [Greg]
| > 
| >>>>import win32api
| >>>>print "Uptime:", win32api.GetTickCount(), "Milliseconds"
| > 
| > Note that in the unlikely event of your Windows machine being up for
| > longer than 2^32 ms (about 49 days), GetTickCount() will 
| wrap back to
| > zero.
| 
| The real solution, in spite of the dozen alternatives we've
| now produced, seems to be to use the win32pdh library
| to access the "System"-> "System Up Time" value.

To add my twopence-ha'penny worth in, the recommended WMI
technique is (apparently) to use the 
Win32_OperatingSystem.LastBootUpTime value:

<code>
import wmi
for i in wmi.WMI ().Win32_OperatingSystem ():
  print i.LastBootUpTime
</code>

The time format is 20041202112313 with some --
apparently unused -- sub-seconds, so you'd have
to faff about a bit with the numbers, but it is
at least usable.

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________



More information about the Python-list mailing list