Re: uptime for Win XP?

Discussion in 'Python' started by Andrey Ivanov, Dec 13, 2004.

  1. [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 :-(
     
    Andrey Ivanov, Dec 13, 2004
    #1
    1. Advertising

  2. Andrey Ivanov

    Peter Hansen Guest

    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
     
    Peter Hansen, Dec 13, 2004
    #2
    1. Advertising

  3. Andrey Ivanov

    David Bolen Guest

    Andrey Ivanov <> 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
     
    David Bolen, Dec 13, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oli Schwarz

    uptime in unix

    Oli Schwarz, Sep 19, 2004, in forum: Python
    Replies:
    8
    Views:
    4,536
    Heiko Wundram
    Sep 20, 2004
  2. Esmail Bonakdarian

    uptime for Win XP?

    Esmail Bonakdarian, Dec 11, 2004, in forum: Python
    Replies:
    24
    Views:
    12,396
    Peter Hansen
    Dec 13, 2004
  3. Andrey Ivanov

    Re: uptime for Win XP?

    Andrey Ivanov, Dec 12, 2004, in forum: Python
    Replies:
    0
    Views:
    446
    Andrey Ivanov
    Dec 12, 2004
  4. Tim Golden

    RE: uptime for Win XP?

    Tim Golden, Dec 13, 2004, in forum: Python
    Replies:
    1
    Views:
    347
    Peter Hansen
    Dec 13, 2004
  5. Krist
    Replies:
    6
    Views:
    768
    Arne Vajhøj
    May 7, 2010
Loading...

Share This Page