uptime for Win XP?

Andrey Ivanov andre1 at yandex.ru
Mon Dec 13 12:21:37 EST 2004


[Peter Hanson]
> 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.  It
> claims to return an 8-byte value, which likely doesn't
> wrap quite so soon.  (And yes, remarkably, with the advent
> of Windows XP Pro it is now possible to keep a Windows
> machine running for longer than 49 days, even if it's
> used as a development machine.  Well, for Python development,
> anyway. ;-)
> 
> For the life of me, however, I can't figure out how to do it.

Here's how. :-)

=================================================================
import win32pdh

query = win32pdh.OpenQuery()
counter = win32pdh.AddCounter(query, r"\System\System Up Time")

win32pdh.CollectQueryData(query)

(bizzare_int, val) = win32pdh.GetFormattedCounterValue(counter, \
        win32pdh.PDH_FMT_LONG)

print "Uptime: %s secs" % (val,)
==================================================================

Writting this script was harder than I initially thought due to
a lack of documentation for win32all. And I still don't know what
that bizzare_int value stands for (an error/status code?).

Well, the registry interface to counters is definitely easier to use,
but not available to Python at the moment :-(




More information about the Python-list mailing list