Windows uptime help

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Windows uptime help

Post by Rain » Thu Mar 09, 2006 4:02 pm

Is there a way to monitor how long windows has been up and running since the last reboot?

Thanks for any help on this.

~Rain

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Mar 09, 2006 4:21 pm

A quick google search found this:
http://support.microsoft.com/kb/232243/en-us

Maybe you could script that?

[/quote]
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Thu Mar 09, 2006 5:17 pm

Thanks for the quick reply, how ever, I came across the same link before I posted my question and can't figure out how to use macro scheduler to monitor the system uptime.

What I would like to do is have macro scheduler run in the back round, check the system uptime and if a system has been up for X number of days or hours open a message window. I'm not sure how to get it to work without using the uptime.exe.

Any way, thank you for your time I will do some more google searching, maybe I can find a different way.

User avatar
JRL
Automation Wizard
Posts: 3502
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Mar 09, 2006 10:30 pm

One simple plan would be to write the time and date to a file as the computer boots up, then write a macro that reads the file and compares it to the "current" time and date.

For Example:
Put the following lines in a .bat file and put that file in the startup folder.

echo | more | time | find "current" > c:\timelog_.txt
echo | more | date | find "current" >> c:\timelog_.txt


every time the computer is rebooted the file c:\timlog_.txt will contain something like:

The current time is: 16:12:52.93
The current date is: 03/09/2006


Reflecting approximate date and time that the computer was booted.

Sorry, if I had more time I'd post a sample script to do the comparison.
Hope this is adequate to give you the concept.

Dick

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Mar 10, 2006 4:49 am

This is how I get the uptime of a remote machine to put on a webpage.

Download and install uptime.exe from microsoft http://www.microsoft.com/ntserver/nts/d ... efault.asp

Script it in macro scheduler with the output redirected to a text file:

Run>cmd /c c:\upt\uptime.exe > c:\upt\uptime.txt

The text file is a single line like:

asffgsdgas has been up for: 0 day(s), 1 hour(s), 46 minute(s), 15 second(s)

You can then use macro scheduler to manipulate that any way you like.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Fri Mar 10, 2006 1:56 pm

Thanks Dick and Me_again those are some great suggestions I don't know why I didn't think of those my self :oops:

~Rain

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Mar 07, 2011 8:32 pm

I know it has been almost 5 years since my original post but I figured better late than never. The code below will display how much time has elapsed since the system was started or rebooted. The time is displayed in Days:Hours:Minutes:Seconds.

Code: Select all

LibFunc>kernel32.dll,GetTickCount,MillisecondsTickCount
Let>SecondsTickCount={%MillisecondsTickCount% DIV 1000}
Let>ElapsedSeconds={Round(%SecondsTickCount%)}
Let>DaysElapsed={%ElapsedSeconds% DIV 86400}
Let>ElapsedSeconds={%ElapsedSeconds% MOD 86400}
Let>HoursElapsed={%ElapsedSeconds% DIV 3600}
Let>ElapsedSeconds={%ElapsedSeconds% MOD 3600}
Let>MinutesElapsed={%ElapsedSeconds% DIV 60}
Let>SecondsElapsed={%ElapsedSeconds% MOD 60}

Length>%DaysElapsed%,Len
if>Len=1
    Let>DaysElapsed=0%DaysElapsed%
endif
Length>%HoursElapsed%,Len
if>Len=1
    Let>HoursElapsed=0%HoursElapsed%
endif
Length>%MinutesElapsed%,Len
if>Len=1
    Let>MinutesElapsed=0%MinutesElapsed%
endif
Length>%SecondsElapsed%,Len
if>Len=1
    Let>SecondsElapsed=0%SecondsElapsed%
endif
mdl>%DaysElapsed%:%HoursElapsed%:%MinutesElapsed%:%SecondsElapsed%

pamarths
Newbie
Posts: 2
Joined: Thu Oct 29, 2009 8:38 am

You can use powershell as well

Post by pamarths » Thu Mar 10, 2011 1:04 pm

You can use powershell as well if you want to do more operations based on uptime.

http://techibee.com/powershell/get-comp ... rshell/659
Thanks,

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts