473,395 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

uptime for Win XP?

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
Jul 18 '05 #1
24 3050
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...
Jul 18 '05 #2
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
Jul 18 '05 #3
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
Jul 18 '05 #4
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

--

Jul 18 '05 #5
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 | nc******@email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
Jul 18 '05 #6
On Sun, 12 Dec 2004 14:25:28 +1000, Nick Coghlan <nc******@iinet.net.au> 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 | nc******@email.com | 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
Jul 18 '05 #7
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>

Jul 18 '05 #8
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
Jul 18 '05 #9
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.
Jul 18 '05 #10
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>

Jul 18 '05 #11
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
Jul 18 '05 #12
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.
Jul 18 '05 #13
On Sun, 12 Dec 2004 09:18:20 -0500, rumours say that Peter Hansen
<pe***@engcorp.com> 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...
Jul 18 '05 #14
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
Jul 18 '05 #15
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
Jul 18 '05 #16
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
Jul 18 '05 #17
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

Jul 18 '05 #18
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
Jul 18 '05 #19
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
Jul 18 '05 #20
Thanks everyone for the great help.

Esmail

Jul 18 '05 #21
Esmail Bonakdarian said unto the world upon 2004-12-12 20:45:
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


Hi Esmail,

try looking for it on your box ;-)

When I recently installed win32all, my Python 2.4 entry on the startmenu
grew a shortcut for "Python for Windows Documentation".

Best,

Brian vdB
Jul 18 '05 #22
Brian van den Broek wrote:
Hi Esmail,

try looking for it on your box ;-)

When I recently installed win32all, my Python 2.4 entry on the startmenu
grew a shortcut for "Python for Windows Documentation".


Ah .. good one!! Thanks. Actually, I thought it might have installed
/integrated it into the IDLE help system which is where I looked for
it. I didn't even think about looking via the start menu. (I have
the command line and IDLE as shortcuts).

Thanks for pointing this out.

Cheers,
Esmail
Jul 18 '05 #23

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


[Greg]
import win32api
print "Uptime:", win32api.GetTickCount(), "Milliseconds"


Note that in the unlikely event of your Windows machine being up for
longer than 2^32 ms (about 49 days), GetTickCount() will wrap back to
zero.

--
Richie Hindle
ri****@entrian.com

Jul 18 '05 #24
Richie Hindle wrote:
[Greg]
import win32api
print "Uptime:", win32api.GetTickCount(), "Milliseconds"


Note that in the unlikely event of your Windows machine being up for
longer than 2^32 ms (about 49 days), GetTickCount() will wrap back to
zero.


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.

-Peter
Jul 18 '05 #25

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Oli Schwarz | last post by:
Hello, how can I read out the uptime of a unix system in python (Linux and *BSD). I have not found a uptime-function in the Library. Regards Oli
6
by: MA | last post by:
Hi all! I know there is other newsgroups for webservices, but I donīt get any answers on those. I have developed a webservice that writeing and reading files in different folders. Question...
4
by: Brian Henry | last post by:
does anyone know of an easy way to say how long has a specific system been up and running? I just need to get back the uptime of the servers on our network for a report, they are all in a Active...
4
by: Dylan Parry | last post by:
Hi, I'm looking for a way to calculate the amount of time that Windows has been running since the last boot. Ideally I'd like to be able to create a DateTime object containing this value so that...
0
by: streamkid | last post by:
hello.. could anyone please help me build a uptime script for openbsd? i tried phpsysinfo, it doesn't work (only uptime works, and that's around 15k days :p) i tried these: <?php...
8
by: Guy Macon | last post by:
How to increase web server uptime with DNS failover: For illustration, let's start with some really bad hosting... Find four free web hosts that are each 90% reliable -- in other words they...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.