Computer Hope

Microsoft => Microsoft DOS => Topic started by: ALAN_BR on August 30, 2008, 09:16:13 AM

Title: How do I get the Time since the computer started ?
Post by: ALAN_BR on August 30, 2008, 09:16:13 AM
I believe Windows has a mSec counter timer which starts at zero upon system start-up,
and I have a "System Resource" tool which includes displays of both normal time (hours, minutes etc.) and also the number of seconds since start-up, proving that what I want is in there somewhere.

Is it possible (and how) for a batch file to also access this Windows timer ?

n.b.  I tried Google, but every search I used either had more than a million hits with nothing relevant on the first page, or zero hits plus advice upon widening my search !!!

Regards
Alan
Title: Re: How do I get the Time since the computer started ?
Post by: Dias de verano on August 30, 2008, 11:12:08 AM
Code: [Select]
@echo off

REM the next line gets the system uptime and converts it into a seconds figure
REM and stores it in the variable %se%
for /f "tokens=1-14 delims= " %%A in ('systeminfo ^| find "System Up Time"') do set /a se=86400*%%D+3600*%%F+60*%%H+%%J

REM demonstrate use
echo System uptime is %se% seconds
Title: Re: How do I get the Time since the computer started ?
Post by: ALAN_BR on August 30, 2008, 01:16:04 PM
Sorry, it did not work, my fault.

I quick search for "systeminfo" now shows me it needs XP Pro.

I am amateur - Windows XP Home with SP3 - sorry I forgot to mention that.

Is the any other way a batch command can extract this data from XP Home,
or is the a small utility I can download as an interface between my batch and XP Home ?

Regards
Alan
Title: Re: How do I get the Time since the computer started ?
Post by: fireballs on August 30, 2008, 01:26:30 PM
try this: http://www.brothersoft.com/systeminfo-82007.html (http://www.brothersoft.com/systeminfo-82007.html)

FB
Title: Re: How do I get the Time since the computer started ?
Post by: Dias de verano on August 30, 2008, 01:28:54 PM
This is the one you want. Save it somewhere on your PATH, for example c:\windows

http://www.rickmaybury.com/Bootarc/toptips_files/systeminfo.exe

Title: Re: How do I get the Time since the computer started ?
Post by: drmsucks on August 30, 2008, 01:30:39 PM
Or this: http://rbytes.net/software/uptime-review/

You  can always look at event viewer to see when the current session started.
Title: Re: How do I get the Time since the computer started ?
Post by: fireballs on August 30, 2008, 01:31:06 PM
you'd have to save the file into c:\windows\system32

FB
Title: Re: How do I get the Time since the computer started ?
Post by: Dias de verano on August 30, 2008, 01:35:02 PM
Or this: http://rbytes.net/software/uptime-review/

You  can always look at event viewer to see when the current session started.

Can it be used from a batch file to get the uptime into a variable, as the OP requested?
Title: Re: How do I get the Time since the computer started ?
Post by: Dias de verano on August 30, 2008, 01:38:47 PM
try this: http://www.brothersoft.com/systeminfo-82007.html (http://www.brothersoft.com/systeminfo-82007.html)

FB

That is a GUI (Windows) app. The OP asked for a method usable from a batch file.

ALAN_BR,

This is the one you want. Save it somewhere on your PATH, for example c:\windows

http://www.rickmaybury.com/Bootarc/toptips_files/systeminfo.exe
Title: Re: How do I get the Time since the computer started ?
Post by: drmsucks on August 30, 2008, 01:57:17 PM
Or this: http://rbytes.net/software/uptime-review/

You  can always look at event viewer to see when the current session started.

Can it be used from a batch file to get the uptime into a variable, as the OP requested?

I doubt it. I noted that the OP requested a batch file but he didn't state a purpose for knowing the uptime. All he said was, "Is it possible (and how) for a batch file to also access this Windows timer ?" If the purpose of the batch file was to answer the question, "How long has my system been up?" then, I think that this link will help. If the purpose of the batch file is to pass on the uptime, it won't.
Title: Re: How do I get the Time since the computer started ?
Post by: Dias de verano on August 30, 2008, 02:04:04 PM
Many people want a method of timing a process that does not involve using the %time% variable.
Title: Re: How do I get the Time since the computer started ?
Post by: ALAN_BR on August 30, 2008, 02:09:25 PM
Thanks

systeminfo is working for me now

"System uptime is 21923 seconds
Press any key to continue . . ."

I have to go now - be back tomorrow.
Thank you

Regards
Alan
Title: Re: How do I get the Time since the computer started ?
Post by: drmsucks on August 30, 2008, 02:14:42 PM
Many people want a method of timing a process that does not involve using the %time% variable.
I know...and many people just want to know how long their system has been running. I cannot know for what purpose Alan wants to know the uptime. But based on this, it doesn't seem critical :)
Thanks

systeminfo is working for me now

"System uptime is 21923 seconds
Press any key to continue . . ."
Title: Re: How do I get the Time since the computer started ?
Post by: Dias de verano on August 30, 2008, 02:21:30 PM
I cannot know for what purpose Alan wants to know the uptime. But based on this, it doesn't seem critical

That's a kind of snooty remark, isn't it? We have no way of knowing what Alan wants to do with a batch file. He has tried out a scheme for extracting uptime data from the output of systeminfo, with a simple script, and sounds satisfied that he can get it to work the way he wants. Who knows what code he will incorporate it in later?
Title: Re: How do I get the Time since the computer started ?
Post by: drmsucks on August 30, 2008, 02:40:42 PM
I cannot know for what purpose Alan wants to know the uptime. But based on this, it doesn't seem critical

That's a kind of snooty remark, isn't it? We have no way of knowing what Alan wants to do with a batch file. He has tried out a scheme for extracting uptime data from the output of systeminfo, with a simple script, and sounds satisfied that he can get it to work the way he wants. Who knows what code he will incorporate it in later?

Not meant to be a snooty remark - for the third time, I believe, I do not know for what purpose Alan wants to know uptime. From the subject of this thread and from his posted comments, I am convinced that he does want to know his system uptime; and, I offered a link to a software item that purports to answer the question. If the answer does not present itself in a form suitable for Alan's purpose, he is more than capable of disregarding it. If he perceives my previous post as "snooty," I will apologize to him.

Title: Re: How do I get the Time since the computer started ?
Post by: Dias de verano on August 30, 2008, 05:42:49 PM
He does not explicitly state that he "wants to know uptime". He wrote...

Quote from: ALAN_BR
I believe Windows has a mSec counter timer ... Is it possible (and how) for a batch file to also access this Windows timer ?

The way he talks about "accessing the timer which starts from zero at system startup" makes me think that he wants to access the system time more than once, for comparative or record-keeping purposes rather than merely to see how long the computer has been running.

ALAN_BR, you can do away with all that systeminfo stuff. Using VBscript, you can access an uptime counter with a resolution of 10 mSec and you can get the reading into a variable in a batch file.

This script should either go in the same folder as the batch file or be placed in a folder that you name in the batch file. In my example batch I placed it in C:\utils. If it is in the same folder as the batch you can just use the bare filename.

VBTimer.vbs

Code: [Select]
Wscript.Echo FormatNumber(timer*1000,0,0,0,0)
Access it in a batch file like this:

Example.bat

Code: [Select]
@echo off
for /f "delims=" %%U in ('cscript //nologo c:\utils\VBTimer.vbs') do set /a uptime=%%U
echo Uptime is %uptime% milliseconds

Output:

Code: [Select]
S:\Test\Vbs>Example.bat
Uptime is 47485300 milliseconds
S:\Test\Vbs>
Title: Re: How do I get the Time since the computer started ?
Post by: drmsucks on August 30, 2008, 11:04:26 PM
Dias - I'm out.
Title: Re: How do I get the Time since the computer started ?
Post by: ALAN_BR on August 31, 2008, 06:23:22 PM
Hi

Please note that
1. I was not offended by any comment therefore I really do not need any apology;
2. I have quite a thick skin, and a very well developed sense of humour;
3. Even if I was offended I would not stay away.   My son still tries to convert me to Vista.   You are like the family and friends I never had - you know and use DOS.   Until I accidentally stumbled across this forum I was convinced that when I died all wisdom would die with me !!!

Back to technical matters.

I told Windows XP to exclude my external drives from System Restore, but sometimes when XP woke up it forgot and reactivated.  I then added prohibitions in the registry, which fixed it until my daughter got an IPOD and I was told I could install iTunes on external drive H:\.  The iTunes setup.exe also thought it could go there, but half way through it aborted.  I then allowed it to install on C:\ and the first thing it did was to automatically remove its residue from H:\ - which I thought was unexpectedly nice of it.  I subsequently realised it had deceived me - it had also taken the opportunity to get System Restore to once more get its claws into my H:\.  I am sorry but my sense of humour fails in this situation.

So I created a batch command file to determine at start-up whether Windows XP was going to stuff Restore Points into my external drives.  Perfect solution.

Then Service Pack 3 got in, and that slowed down some things.  In particular there was only an 80% probability that System Restore would have posted today's status before my batch file examined its contents in C:\SYSTEM~1\_RESTO~1\DRIVET~1.TXT.

That is when I came to this forum and found that I could "START" a program in /LOW priority mode, so I made my batch file invoke the status examination in low priority mode, hence it did not start to look at status until the frantic hubbub of start-up was finished.  Perfect solution.

Then I find with SP3 there is a far higher probability that "systray" icons will be lost at start-up, so I removed some items from the start-up folder to reduce the start-up processing, and added /WAIT to my START, and the main batch command file now launches what I removed from start-up.  Much better, but still not always good.

So I added diagnostic time stamps such as :-
29/08/2008 19:50:44.25 TO 19:51:09.16/19:51:10.72/19:51:11.43 19:51:14.69
30/08/2008 8:40:50.32 TO  8:41:05.11/ 8:41:12.76/ 8:41:18.08  8:41:35.27
30/08/2008 15:02:43.25 TO 15:02:59.29/15:03:01.17/15:03:02.24 15:03:09.67
30/08/2008 21:59:39.56 TO 21:59:56.02/21:59:57.85/21:59:58.98 22:00:01.13
31/08/2008 8:23:45.68 TO  8:24:00.97/ 8:24:02.57/ 8:24:03.22  8:24:20.43
31/08/2008 13:15:02.76 TO 13:15:34.76/13:15:36.36/13:15:40.16 13:15:43.36
31/08/2008 15:53:32.15 TO 15:53:45.44/15:53:47.29/15:53:48.63 15:53:51.19
31/08/2008 20:57:27.56 TO 20:57:45.22/20:57:47.70/20:57:48.41 20:57:50.50

I decided I would have a far better view of the diagnostics if they were all relative to start-up, rather than G.M.T.   I saw a thread about calculating time differences, but decided that my very compact batch file would be overwhelmed with all the extra processing for all the "supplementary" diagnostics.  Hence my request for a counter that starts at zero on start-up.

I came back to report that I can do the job with
systeminfo | find "System Up Time" > GOTe(%1).TXT

BUT it takes about 4 seconds to do it.

With extra complications I can START a timestamp and immediately move on to do other things and start other timestamps.  If I start 10 timestamps at 0.1 second intervals they all grab a number that is within 5 seconds of the first one, but they tend to swap timing order, and the subsequent spewing out and through the FIND filter takes another 40 seconds.

Dias - I love you last solution.  It works.  It meets all my desires.

I knew I could get whatever this register was if I coded in 'C' - but the last time I did that was on Windows 95 and I thought it would endanger XP unless I upgraded my tools.  I thought any other way of coding to "get inside" Windows, such as Visual Basic, would cost money and a steep learning curve.

You make it look so simple.  I would appreciate it greatly if you could post me a link so I may learn more about VB scripts.

Regards
A very happy Alan
Title: Re: How do I get the Time since the computer started ?
Post by: ALAN_BR on September 11, 2008, 07:36:36 AM
I would appreciate a link to further information upon the use of
"Wscript.Echo FormatNumber(timer*1000,0,0,0,0)", and the many other parameters that can be evaluated.

I assume that there is a lot more information available than "timer" if only I could find a reference manual with an index.  Goggle found 86,100,000 hits within 0.14 Seconds - but it would take me MUCH longer than that to find anything relevant.  Searching for "Wscript.Echo" was more rewarding, BUT it all seemed to link to long articles and complex scripts - I am hoping to find some simple one line exercises that I can try out before I learn yet another completely new-to-me programming language

I now have a good diagnostic summary of timestamps showing when various start-up process complete.  My original goal of timestamps relative to start-up has now been revised - some processes randomly take much longer than normal and delay everything that follows.  Now I subtract each timestamp from the previous and report the duration of each process, so when a process takes longer it no longer affects subsequent results.

Regards
Alan
Title: Re: How do I get the Time since the computer started ?
Post by: Dias de verano on September 11, 2008, 11:59:18 AM
I'm sorry I didn't answer your previous query; the truth is I haven't got any single place I use for vbscript resources, I just tend to Google for whatever topic I need help with e.g. searching for "vbscript timer".

I'll break down that Wscript.echo line for you:

Wscript.echo echoes whatever follows, if you use cscript as the script engine, it uses the console.

FormatNumber works like this

Wscript.echo FormatNumber (number or expression, NumDigitsAfterDecimal, IncludeLeadingDigit, UseParensForNegativeNumbers, GroupDigits)


The 4 parameters after the number work like this. In the line you are referring to, they are all zero

NumDigitsAfterDecimal - value indicating how many places to the right of the decimal are displayed. The default value is -1, indicating that regional settings should be used. (Optional)

IncludeLeadingDigit - indicates whether or not a leading zero is displayed for fractional values. (Optional)

    -1 = True
     0 = False
    -2 = Use regional settings

UseParensForNegativeNumbers - indicates whether or not to place negative values within parentheses. (Optional)

    -1 = True
     0 = False
    -2 = Use regional settings

GroupDigits - indicates whether or not numbers are grouped using the group delimiter specified in the Windows Control Panel. (Optional) (I.e. comma, space or dot for every 3 digits in numbers 1000 and over)

    -1 = True
     0 = False
    -2 = Use regional settings

Actually the site I link to below is a very good resource with examples.

http://www.adminscripteditor.com/syntax.asp?l=v&lim=1





Title: Re: How do I get the Time since the computer started ?
Post by: ALAN_BR on September 11, 2008, 03:11:33 PM
Thank you for the detailed explanation whcih answers all my immediate questions.

Thank you also for the link, which looks very useful for future explorations.

Regards
Alan