Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: uptime for Win XP?

Reply
Thread Tools

Re: uptime for Win XP?

 
 
Andrey Ivanov
Guest
Posts: n/a
 
      12-13-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

 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      12-13-2004
Andrey Ivanov wrote:
> [Peter Hanson]
>>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")


Argh! A _leading backslash_ !!

(Thanks.

-Peter
 
Reply With Quote
 
 
 
 
David Bolen
Guest
Posts: n/a
 
      12-13-2004
Andrey Ivanov <(E-Mail Removed)> writes:

(...)
> 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?).


The pywin32 documentation tends not to duplicate information already
available via MSDN (whether in a local installation or at
msdn.microsoft.com) on the underlying Win32 API, so when in doubt,
that's where to look. Then, the pywin32 documentation will sometimes
qualify how the Python interface maps that function.

But in particular, a general rule (as has already been posted) is that
any out parameters are aggregated along with the overall result code
into a result tuple.

-- David
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Applet to run on Win 98, Win ME, Win XP, Win Vista & Win 7 ?? Krist Java 6 05-06-2010 11:53 PM
RE: uptime for Win XP? Tim Golden Python 1 12-13-2004 05:47 PM
uptime for Win XP? Esmail Bonakdarian Python 24 12-13-2004 03:12 PM
Re: uptime for Win XP? Andrey Ivanov Python 0 12-12-2004 11:02 AM
5509 uptime Trash Cisco 2 11-16-2003 11:52 PM



Advertisments