uptime for Win XP?

Discussion in 'Python' started by Esmail Bonakdarian, Dec 11, 2004.

  1. Hi,

    Is there a way to display how long a Win XP system has been up?
    Somewhat analogous to the *nix uptime command.

    Thanks,
    Esmail
     
    Esmail Bonakdarian, Dec 11, 2004
    #1
    1. Advertising

  2. Esmail Bonakdarian

    Tom Wesley Guest

    Esmail Bonakdarian wrote:
    > Hi,
    >
    > Is there a way to display how long a Win XP system has been up?
    > Somewhat analogous to the *nix uptime command.
    >
    > Thanks,
    > Esmail


    I believe that "uptime" works from the console, but don't have a machine
    to check it with...
     
    Tom Wesley, Dec 11, 2004
    #2
    1. Advertising

  3. Esmail Bonakdarian

    Greg Krohn Guest

    Tom Wesley wrote:
    > Esmail Bonakdarian wrote:
    >
    >> Hi,
    >>
    >> Is there a way to display how long a Win XP system has been up?
    >> Somewhat analogous to the *nix uptime command.
    >>
    >> Thanks,
    >> Esmail

    >
    >
    > 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

    hth
    greg
     
    Greg Krohn, Dec 11, 2004
    #3
  4. Esmail Bonakdarian

    Peter Hansen Guest

    Tom Wesley wrote:
    > Esmail Bonakdarian wrote:
    >
    >> Is there a way to display how long a Win XP system has been up?
    >> Somewhat analogous to the *nix uptime command.

    >
    > I believe that "uptime" works from the console, but don't have a machine
    > to check it with...


    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    c:\>uptime
    'uptime' is not recognized as an internal or external command,
    operable program or batch file.


    Not here, at any rate. Maybe it's part of the Productivity Kit
    thingy?

    -Peter
     
    Peter Hansen, Dec 12, 2004
    #4
  5. IIRC, i think it's part of the powertools or IT Toolkit

    Peter Hansen said:
    > Tom Wesley wrote:
    >> Esmail Bonakdarian wrote:
    >>
    >>> Is there a way to display how long a Win XP system has been up?
    >>> Somewhat analogous to the *nix uptime command.

    >>
    >> I believe that "uptime" works from the console, but don't have a machine
    >> to check it with...

    >
    > Microsoft Windows XP [Version 5.1.2600]
    > (C) Copyright 1985-2001 Microsoft Corp.
    >
    > c:\>uptime
    > 'uptime' is not recognized as an internal or external command,
    > operable program or batch file.
    >
    >
    > Not here, at any rate. Maybe it's part of the Productivity Kit
    > thingy?
    >
    > -Peter
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >



    --
     
    Jonel Rienton, Dec 12, 2004
    #5
  6. Esmail Bonakdarian

    Nick Coghlan Guest

    Esmail Bonakdarian wrote:
    > Hi,
    >
    > Is there a way to display how long a Win XP system has been up?
    > Somewhat analogous to the *nix uptime command.
    >
    > Thanks,
    > Esmail


    It's included in the output of the 'systeminfo' command. That command is fairly
    slow, though (since it displays a lot more than just the up time)

    There's also info about the 'uptime' utility here:
    http://support.microsoft.com/kb/q232243/

    I don't know if that works for XP.

    Cheers,
    Nick.

    --
    Nick Coghlan | | Brisbane, Australia
    ---------------------------------------------------------------
    http://boredomandlaziness.skystorm.net
     
    Nick Coghlan, Dec 12, 2004
    #6
  7. On Sun, 12 Dec 2004 14:25:28 +1000, Nick Coghlan <> wrote:

    >Esmail Bonakdarian wrote:
    >> Hi,
    >>
    >> Is there a way to display how long a Win XP system has been up?
    >> Somewhat analogous to the *nix uptime command.
    >>
    >> Thanks,
    >> Esmail

    >
    >It's included in the output of the 'systeminfo' command. That command is fairly
    >slow, though (since it displays a lot more than just the up time)
    >
    >There's also info about the 'uptime' utility here:
    >http://support.microsoft.com/kb/q232243/
    >
    >I don't know if that works for XP.
    >
    >Cheers,
    >Nick.
    >
    >--
    >Nick Coghlan | | Brisbane, Australia
    >---------------------------------------------------------------
    > http://boredomandlaziness.skystorm.net


    >>> import os
    >>> [x for x in os.popen('pstat') if 'uptime' in x.lower()]

    ['Pstat version 0.3: memory: 327080 kb uptime: 4 15:44:16.696 \n']

    That is, if pstat.exe is on your system and path. It comes with various sdk's
    and Visual studio stuff. Check tools subdirectory under the latter.
    Pstat prints a snapshot of pmon plus drivers info which means info about every process
    and thread running as well as drivers loaded, so the above threw away a lot of lines to get the one:

    [23:38] C:\pywk\clp>pstat|wc
    442 3350 27404

    ;-)
    There's got to be something leaner though.

    Regards,
    Bengt Richter
     
    Bengt Richter, Dec 12, 2004
    #7
  8. Esmail Bonakdarian wrote:

    > Is there a way to display how long a Win XP system has been up?
    > Somewhat analogous to the *nix uptime command.


    ugly, somewhat slow, and possibly locale dependent:

    import os, re

    def uptime():
    return re.search(
    "System Up Time:\s*(.+)", os.popen("systeminfo").read()
    ).group(1)

    print uptime()

    </F>
     
    Fredrik Lundh, Dec 12, 2004
    #8
  9. Esmail Bonakdarian

    Peter Hansen Guest

    Bengt Richter wrote:
    > >>> import os
    > >>> [x for x in os.popen('pstat') if 'uptime' in x.lower()]

    > ['Pstat version 0.3: memory: 327080 kb uptime: 4 15:44:16.696 \n']
    >

    [...]

    > There's got to be something leaner though.


    I believe there is, though I can't guarantee this is a
    valid approach:

    >>> import datetime
    >>> import os
    >>> def uptime():

    .... t = os.stat('c:/pagefile.sys').st_mtime
    .... td = datetime.datetime.now() - datetime.datetime.fromtimestamp(t)
    .... return td
    ....
    >>> print uptime()

    12 days, 20:21:17.491000

    (matches results of Bengt's and Fredrik's two approaches
    two within a minute or so)

    -Peter
     
    Peter Hansen, Dec 12, 2004
    #9
  10. Esmail Bonakdarian

    Brad Tilley Guest

    Esmail Bonakdarian wrote:
    > Hi,
    >
    > Is there a way to display how long a Win XP system has been up?
    > Somewhat analogous to the *nix uptime command.
    >
    > Thanks,
    > Esmail


    Just run the built-in Windows utility 'systeminfo' from a cmd prompt.
    Python can call 'systeminfo' like this:

    import os

    uptime = os.popen('systeminfo', 'r')
    data = uptime.readlines()
    uptime.close

    for line in data:
    if line contains "System Up Time":
    print line

    Please note that 'systeminfo' is only present on Windows XP PRO and
    Windows Server 2003... Windows XP HOME does not have this command.
     
    Brad Tilley, Dec 12, 2004
    #10
  11. Brad Tilley wrote

    > Just run the built-in Windows utility 'systeminfo' from a cmd prompt.


    you're a bit late, aren't you?

    > for line in data:
    > if line contains "System Up Time":
    > print line


    what Python version is this?

    </F>
     
    Fredrik Lundh, Dec 12, 2004
    #11
  12. Esmail Bonakdarian

    Brad Tilley Guest

    Fredrik Lundh wrote:
    > Brad Tilley wrote
    >
    >
    >>Just run the built-in Windows utility 'systeminfo' from a cmd prompt.

    >
    >
    > you're a bit late, aren't you?
    >
    >
    >>for line in data:
    >> if line contains "System Up Time":
    >> print line

    >
    >
    > what Python version is this?


    Sorry, lang mix-up:

    x = "System Up Time"
    if x in line:
    print line
     
    Brad Tilley, Dec 12, 2004
    #12
  13. Esmail Bonakdarian

    Peter Hansen Guest

    Fredrik Lundh wrote:
    > you're a bit late, aren't you?


    Or a lot early, perhaps. ;-)

    >>for line in data:
    >> if line contains "System Up Time":
    >> print line

    >
    > what Python version is this?


    Python 2.7, natch.
     
    Peter Hansen, Dec 12, 2004
    #13
  14. Re: uptime for Win XP? --plus OT rantings for the same price

    On Sun, 12 Dec 2004 09:18:20 -0500, rumours say that Peter Hansen
    <> might have written:

    >Bengt Richter wrote:
    >> >>> import os
    >> >>> [x for x in os.popen('pstat') if 'uptime' in x.lower()]

    >> ['Pstat version 0.3: memory: 327080 kb uptime: 4 15:44:16.696 \n']
    >>

    >[...]
    >
    >> There's got to be something leaner though.


    [Peter]
    >I believe there is, though I can't guarantee this is a
    >valid approach:
    >
    > >>> import datetime
    > >>> import os
    > >>> def uptime():

    >... t = os.stat('c:/pagefile.sys').st_mtime
    >... td = datetime.datetime.now() - datetime.datetime.fromtimestamp(t)
    >... return td
    >...
    > >>> print uptime()

    >12 days, 20:21:17.491000


    >(matches results of Bengt's and Fredrik's two approaches
    >two within a minute or so)


    Well, that's a good idea (assuming mtime does not change with pagefile
    size adjustment), but without guaranteed portability; eg. it wouldn't
    work on my machine.

    OT stuff from now on:

    I went into a lot of trouble to make sure that *no* pagefile.sys would
    be on my c: drive, mainly for speed reasons. Windows XP is very
    stubborn and surely knows better than the poor luser who wants to
    configure quantity, size and whereabouts of their swap files... So on
    my machine, C:\pagefile.sys is an empty directory without any
    permissions at all. The no permissions bit is actually unnecessary
    (after all, like lab microorganisms, XP "will do as they damn please")
    but it sure felt better: think along the lines, "now, sit there, and
    *stay* there."

    Observations for a machine with 512 MiB RAM (after LOTS of re-boots),
    XP/SP2:

    {setting}
    - {result}

    "no swapfile anywhere"
    - no swap files anywhere

    "let windows manage my virtual memory":
    - c:\pagefile.sys 766MiB

    "no swap on c:, 8-766MiB on d":
    - c:\pagefile.sys 766MiB, d:\pagefile.sys 8MiB

    "8-8 MiB on c:, 766MiB on c":
    - c:\pagefile.sys 766MiB, d:\pagefile.sys 766MiB

    You see a pattern here, right? So I set no swap files at all, reboot,
    create an empty c:\pagefile.sys, do attrib +h +r -s for the fun of it,
    then remove *all* permissions on it. Set your swapfile to no swap file
    on c:, whatever on d:. Reboot. Hi, beauty, what's your size? 766 MiB.

    Like I said, making a c:\pagefile.sys directory solved my problem. And,
    guess what? My machine works fine when booting windoze. It also helps
    that I have shut down almost everything not needed, so after booting,
    Task Manager shows 14 processes (including itself, Idle and System
    processes) and 67 MiB of memory used.

    Of course, if I want to start the Infrared service, I *have* to start
    Terminal Services first (which can't be shut down afterwards). Thank
    $god for Python (for a little bit of on-topicness) and pywin, I have
    little scripts that start / stop everything needed per task.

    And why do I run Windoze in the first place? Because the CRM and issue
    tracking software we use, written in Delphi by another company obscurely
    related to my company, does not run under Wine whatever I tried (it
    crashes). The app initially crashed on my Windows too, and it didn't
    take long to understand that the reason was I use ISO date format
    (yyyy-mm-dd), while all others use the default greek format
    (dd/mm/yyyy), so presumably the program couldn't parse the default date
    criteria *it* sent to the underlying Borland database engine.

    I sent a bug report, never got a reply, don't know if I will. Until I
    get some feedback, a Python script calls ctype.kernel32 stuff, changes
    the date format, runs the app, and restores things on completion. The
    icon on my desktop for the script comes from shell32.dll, the one
    portraying the green sign for handicapped people; no offense meant for
    the real handicapped people, but I couldn't find a sign for
    internationalisation-and-functionality-challenged programs... Is there
    one?


    PS. another bit of trivia for the curious mind:

    Remove any access permission from the system32\dllcache for the SYSTEM
    user (or force it to no permissions at all for anyone) on a Win2K
    machine (untested on XP). Reboot.
    Measure your machine's performance in rpm (reboots per minute).

    To restore things, use the recovery console or whatever it is called
    from the Win2K installation CD to give back permissions.


    PS2. By the way, isn't CreateHardLink a great function, even if only
    existing for POSIX conformance without command-line availability? I
    mean, once a week I scan the windows folder and hard-link files that are
    the same (eg DLLs in system32 and dllcache folders). That process frees
    about 160MiB on my c: drive. I guess this cancels all the security
    benefits I (maybe) get from Windows against bad DLL installations...
    what the heck, I don't even run antivirus programs[1]. Incidentally,
    the dupefind.py script that does this linking works fine (better) on
    *nix systems; at the least, on *nix stat returns a meaningful st_inum
    and you know which files are hard links already and who aren't.

    OK, I better shut up now and go to sleep.

    [1] ...and got infected only twice in 13 years with PCs, which I found
    out and dealt with very quickly. And yes, I would be interested in a
    car with just a "?" sign on the dashboard :)
    --
    TZOTZIOY, I speak England very best.
    "Be strict when sending and tolerant when receiving." (from RFC1958)
    I really should keep that in mind when talking with people, actually...
     
    Christos TZOTZIOY Georgiou, Dec 13, 2004
    #14
  15. Tom Wesley wrote:
    >
    > I believe that "uptime" works from the console, but don't have a machine
    > to check it with...


    Hi Tom,

    no, unfortunately not.

    Esmail
     
    Esmail Bonakdarian, Dec 13, 2004
    #15
  16. Greg Krohn wrote:
    > if you have win32all installed, you can get it
    > from Python:
    >
    > >>> import win32api
    > >>> print "Uptime:", win32api.GetTickCount(), "Milliseconds"

    > Uptime: 148699875 Milliseconds



    Hi Greg!

    Thanks, that was usefull, esp since I had no idea about the win32api
    which I promptly downloaded ;-)

    However, I don't seem to be able to find a good place that documents
    this. I downloade this from sourceforge but didn't see docs there (did
    I miss this?)

    Do you have a URL for docs?

    Thanks again!

    Esmail
     
    Esmail Bonakdarian, Dec 13, 2004
    #16
  17. Nick Coghlan wrote:
    >
    > It's included in the output of the 'systeminfo' command. That command is
    > fairly slow, though (since it displays a lot more than just the up time)
    >
    > There's also info about the 'uptime' utility here:
    > http://support.microsoft.com/kb/q232243/
    >
    > I don't know if that works for XP.


    Hi Nick,

    Thanks for the link, odd that XP isn't listed in the list of
    systems.

    Esmail
     
    Esmail Bonakdarian, Dec 13, 2004
    #17
  18. Bengt Richter wrote:
    > >>> import os
    > >>> [x for x in os.popen('pstat') if 'uptime' in x.lower()]

    > ['Pstat version 0.3: memory: 327080 kb uptime: 4 15:44:16.696 \n']
    >
    > That is, if pstat.exe is on your system and path. It comes with various sdk's
    > and Visual studio stuff. Check tools subdirectory under the latter.


    Wow, one more way, I have VS .NET installed, I'll look for it.

    Thanks!

    Esmail

    > Pstat prints a snapshot of pmon plus drivers info which means info about every process
    > and thread running as well as drivers loaded, so the above threw away a lot of lines to get the one:
    >
    > [23:38] C:\pywk\clp>pstat|wc
    > 442 3350 27404
    >
    > ;-)
    > There's got to be something leaner though.
    >
    > Regards,
    > Bengt Richter
     
    Esmail Bonakdarian, Dec 13, 2004
    #18
  19. Peter Hansen wrote:

    >
    > I believe there is, though I can't guarantee this is a
    > valid approach:
    >
    > >>> import datetime
    > >>> import os
    > >>> def uptime():

    > ... t = os.stat('c:/pagefile.sys').st_mtime
    > ... td = datetime.datetime.now() - datetime.datetime.fromtimestamp(t)
    > ... return td
    > ...
    > >>> print uptime()

    > 12 days, 20:21:17.491000
    >
    > (matches results of Bengt's and Fredrik's two approaches
    > two within a minute or so)


    Wow .. this seems to work off-the-bat, thanks a lot!!

    Esmail
     
    Esmail Bonakdarian, Dec 13, 2004
    #19
  20. Fredrik Lundh wrote:

    > import os, re
    >
    > def uptime():
    > return re.search(
    > "System Up Time:\s*(.+)", os.popen("systeminfo").read()
    > ).group(1)
    >
    > print uptime()


    Thanks, I'm learning a lot :)

    Esmail
     
    Esmail Bonakdarian, Dec 13, 2004
    #20
    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,539
    Heiko Wundram
    Sep 20, 2004
  2. Andrey Ivanov

    Re: uptime for Win XP?

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

    RE: uptime for Win XP?

    Tim Golden, Dec 13, 2004, in forum: Python
    Replies:
    1
    Views:
    348
    Peter Hansen
    Dec 13, 2004
  4. Andrey Ivanov

    Re: uptime for Win XP?

    Andrey Ivanov, Dec 13, 2004, in forum: Python
    Replies:
    2
    Views:
    409
    David Bolen
    Dec 13, 2004
  5. Krist
    Replies:
    6
    Views:
    771
    Arne Vajhøj
    May 7, 2010
Loading...

Share This Page