uptime for Win XP?

E

Esmail Bonakdarian

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
 
T

Tom Wesley

Esmail said:
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...
 
G

Greg Krohn

Tom said:
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:
Uptime: 148699875 Milliseconds

hth
greg
 
P

Peter Hansen

Tom said:
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
 
J

Jonel Rienton

IIRC, i think it's part of the powertools or IT Toolkit

Peter Hansen said:
Tom said:
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


--
 
N

Nick Coghlan

Esmail said:
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.
 
B

Bengt Richter

Esmail said:
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 | (e-mail address removed) | 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
 
F

Fredrik Lundh

Esmail said:
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>
 
P

Peter Hansen

Bengt said:
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:
.... t = os.stat('c:/pagefile.sys').st_mtime
.... td = datetime.datetime.now() - datetime.datetime.fromtimestamp(t)
.... return td
....12 days, 20:21:17.491000

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

-Peter
 
B

Brad Tilley

Esmail said:
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.
 
B

Brad Tilley

Fredrik said:
Brad Tilley wrote




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




what Python version is this?

Sorry, lang mix-up:

x = "System Up Time"
if x in line:
print line
 
C

Christos TZOTZIOY Georgiou

Bengt said:
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:
... t = os.stat('c:/pagefile.sys').st_mtime
... td = datetime.datetime.now() - datetime.datetime.fromtimestamp(t)
... return td
...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 :)
 
E

Esmail Bonakdarian

Greg said:
if you have win32all installed, you can get it
from Python:

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
 
E

Esmail Bonakdarian

Nick said:
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
 
E

Esmail Bonakdarian

Bengt said:
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
 
E

Esmail Bonakdarian

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

... t = os.stat('c:/pagefile.sys').st_mtime
... td = datetime.datetime.now() - datetime.datetime.fromtimestamp(t)
... return td
...
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
 
E

Esmail Bonakdarian

Fredrik said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top