Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch File to increment counter

Status
Not open for further replies.

shawkz

Programmer
Oct 25, 2005
84
0
0
GB
Hi, i have some pc's which i leave on test rebooting every 60 seconds. I want to be able to create a log file which includes the current date & time also the number of reboots..

I.e

Date/Time Counter
02/03/2007 08:00:00 1
02/03/2007 08:01:00 2
02/03/2007 08:02:00 3
02/03/2007 08:03:00 4
02/03/2007 08:04:00 5

Please can someone show me how to do this?

Kindest thanks,
SH
 
Instead of a batch file it may be easier to create a VBS script (saved to the PC's startup folder) and use the registry to maintain the count:

For example, a VBS script would need to:

1) Check for the existence of a file (using the FileExists method of the FileSystemObject).
2) If the file exists then go to 6 below or, if the file does not exist, create a file (using the CreateTextFile method).
3) Open the file for writing (using the OpenTextFile method) and write the date and time, a space or tab then the figure 1 then a new line.
4) Close the file for writing.
5) Write the value 1 to the registry (using the RegWrite method of the WshShell object) then exit the script.
6) Check for the existence of or just read the value of the registry key (using the RegRead method), increment it by 1 and write the value back to the registry.
7) Open the file for appending.
8) Write the date and time, a space or tab then the value from the registry then a new line
9) Close the file for writing and exit the script.

You can find examples of how to use all these methods in Tek-Tips' VBScript forum.

Have a look at for more examples of the RegWrite and RegRead methods.

Have a look at for more examples of using the FileSystemOject.

For the date and time in the format you want you can use:

Code:
strDateTime = date()& " " & time()

Hope this helps...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top