Saved Bookmarks
| 1. |
Solve : How do I get the Time since the computer started ?? |
|
Answer» He does not explicitly state that he "wants to know uptime". He wrote... 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>Dias - I'm out.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 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 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 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 |
|