uptime for Win XP?
Andrey Ivanov
andre1 at yandex.ru
Sun Dec 12 06:02:43 EST 2004
>> I believe that "uptime" works from the console, but don't have a machine
>> to check it with...
> Doesn't work for me, but if you have win32all installed, you can get it
> from Python:
> >>> import win32api
> >>> print "Uptime:", win32api.GetTickCount(), "Milliseconds"
> Uptime: 148699875 Milliseconds
MSDN recommends another approach. They say, that you should retrieve
the value of "System Up Time" counter from HKEY_PERFORMANCE_DATA. In
theory, you can do it without win32all, by using _winreg module. All
you need is to know a counter index, which can be fetched from
registry. On my system "System Up Time" counter has index "674", so
Python code should look like this:
>>> import _winreg
>>> value, type_code = _winreg.QueryValueEx(_winreg.HKEY_PERFORMANCE_DATA, "674")
>>> print "Uptime: %s miliseconds" % (value,)
But in current implementation of _winreg it doesn't work. I've checked
the sources and found that current implementation doesn't handle
ERROR_MORE_DATA, which prevents it from retrieving any performance
counters. I'm thinking of bug/patch submission.
More information about the Python-list
mailing list