The supplier told us just to turn back clock until new version arrived which was late.
However this of course would mean that everyone's clocks and dates would be all over the place and potentially could cause problems especially with accounting software.
So... I wrote this batch file that when you click it it does the following
1. Gets todays date
2. Changes the month and tells the computer to be that date
3. Writes another batch file (in the same dir its run from) temporarily
that the first one will call (reasons to follow)
4. Calls the written batch file (which incidentally calls the program that
is located in the new batch file)
5. Puts the date back to normal
6. Pings nothing / to delay the batch file
7. closes (leaving program running)
I've annotated it somewhat more since writing it earlier today
Oh... yeah reasons for stuff...
Writing a batch file that writes a batch file which calls a program
sounds a bit arse about face.
But the reason being - if you call the program directly from the batch file
, the batch file cant continue on and change the date back until you close the program you opened originally. which makes it pointless.
So. it writes a batch file which opens the program - so the focus of the original batch is relieved (if you like) allowing it to continue on (after a delay) and change the date back again... make sense ?
The reason for a batch - its easy to write - quick and can be run in windows from a central store without issue.
@ECHO OFF
:: ----- -- DATE CHANGER FOR ------ COCKUP -----
:: ----- -- CREATED BY CHRIS GAVIN-EGAN
:: ----- -- AMPS.co.nz
:: IGNORE THIS LINE
:: IGNORE THIS ONE TOO (written previously) SET PROGRAMLOCATION="TW2.BAT"
:: -------------------------------------
:: -------------------------------------
:: -------------------------------------------
::THESE LINES WRITES THE NEW BATCH FILE
:: /D "C:\program files...." is the folder that it starts in
:: /B starts cmd in same window
:: /Seperate cmd in new process
:: /normal - run it at normal process speed
:: INET4EPC.EXE is the program we're trying to run
:: ---------------------------------------
ECHO start /B /D "C:\Program Files\Triumph EPC" /SEPARATE /NORMAL INET4EPC.exE >TW3.BAT
:: Add exit to the batch file
ECHO exit >>TW3.BAT
:: ---------------------------------------
:: Clear the screen and let people know whats happening
:: ---------------------------------------
cls
ECHO.
ECHO.
ECHO.
ECHO.
ECHO CHANGING DATE ONE MONTH BACK
ECHO WILL NOW THE PROGRAM
ECHO WHEN FINISHED - HIT RETURN TO RESTORE DATE
ECHO.
ECHO.
echo.
::SET THINGS UP
:: GET TODAYS DATE
for /F "tokens=1 delims=/- " %%A in ('date/T') do set varday=%%A
for /F "tokens=2 delims=/- " %%A in ('date/T') do set vardays=%%A
for /F "tokens=3 delims=/- " %%A in ('date/T') do set varmonth=%%A
for /F "tokens=4 delims=/- " %%A in ('date/T') do set varyear=%%A
:: ---------------------------------------
:: this var not used in this prog -------
:: ---------------------------------------
for /F "tokens=2-4 delims=/- " %%A in ('date/T') do set var=%%C%%A%%B
:: ---------------------------------------
:: ---------------------------------------
:: --- find month and set new variable ----
:: -------- then jump further down -------
:: ---------------------------------------
if %varmonth%==12 set varchanged=11
if %varmonth%==12 goto setback
if %varmonth%==11 set varchanged=10
if %varmonth%==11 goto setback
if %varmonth%==10 set varchanged=09
if %varmonth%==10 goto setback
if %varmonth%==09 set varchanged=08
if %varmonth%==09 goto setback
if %varmonth%==08 set varchanged=07
if %varmonth%==08 goto setback
if %varmonth%==07 set varchanged=06
if %varmonth%==07 goto setback
if %varmonth%==06 set varchanged=05
if %varmonth%==06 goto setback
if %varmonth%==05 set varchanged=04
if %varmonth%==05 goto setback
if %varmonth%==04 set varchanged=03
if %varmonth%==04 goto setback
if %varmonth%==03 set varchanged=02
if %varmonth%==03 goto setback
if %varmonth%==02 set varchanged=01
if %varmonth%==02 goto setback
if %varmonth%==01 set varchanged=12
:: ----------------------------------------------
:: --- this line ACTUALLYS CHANGES the date ----
:: ----------------------------------------------
:setback
date=%vardays%-%varchanged%-%varyear%
:: ----------------------------------------------
:: -- THIS CALLS THE BATCH FILE WRITTEN EARLIER --
:: ----------------------------------------------
START TW3.BAT
cls
:: ----------------------------------------------
:: -- THIS STRANGE PING COMMAND - DELAYS THINGS 15 SECS
:: -- JUST LONG ENOUGH FOR THE PROGRAM TO START
:: -- PING USED BECAUSE IT JUST WORKS EVEN WHEN NOTHING TO PING --
:: -- CHANGE 15000 to something bigger if you need it
:: ----------------------------------------------
PING 1.1.1.1 -n 1 -w 15000 >NUL
:: -----------IGNORE LINE BELOW - OLD VERSION ---
::START %PROGRAMLOCATION%
ECHO.
ECHO.
ECHO.
ECHO.
ECHO PRESS ANOTHER KEY TO
ECHO RESTORE THE DATE
ECHO.
ECHO.
ECHO.
echo.
:: ---------------------------------------
:: --- find month and set OLD MONTH variable ----
:: -------- then jump further down -------
:: ---------------------------------------
:: GET TODAYS DATE
for /F "tokens=1 delims=/- " %%A in ('date/T') do set varday=%%A
for /F "tokens=2 delims=/- " %%A in ('date/T') do set vardays=%%A
for /F "tokens=3 delims=/- " %%A in ('date/T') do set varmonth=%%A
for /F "tokens=4 delims=/- " %%A in ('date/T') do set varyear=%%A
for /F "tokens=2-4 delims=/- " %%A in ('date/T') do set var=%%C%%A%%B
if %varmonth%==12 set varchanged=01
if %varmonth%==12 goto setforward
if %varmonth%==11 set varchanged=12
if %varmonth%==11 goto setforward
if %varmonth%==10 set varchanged=11
if %varmonth%==10 goto setforward
if %varmonth%==09 set varchanged=10
if %varmonth%==09 goto setforward
if %varmonth%==08 set varchanged=09
if %varmonth%==08 goto setforward
if %varmonth%==07 set varchanged=08
if %varmonth%==07 goto setforward
if %varmonth%==06 set varchanged=07
if %varmonth%==06 goto setforward
if %varmonth%==05 set varchanged=06
if %varmonth%==05 goto setforward
if %varmonth%==04 set varchanged=05
if %varmonth%==04 goto setforward
if %varmonth%==03 set varchanged=04
if %varmonth%==03 goto setforward
if %varmonth%==02 set varchanged=03
if %varmonth%==02 goto setforward
if %varmonth%==01 set varchanged=02
:: ----------------------------------------------
:: --- this line ACTUALLYS CHANGES the date ----
:: ----------------------------------------------
:setforward
date=%vardays%-%varchanged%-%varyear%
:: ----------------------------------------------
:: --- this line CHECKS FOR BATCH FILE AND DELETES IT ----
:: ----------------------------------------------
iF EXIST TW3.BAT ERASE TW3.BAT
:: ----------------------------------------------
:: --- this line CLOSES THE BATCH FILE ----
:: ----------------------------------------------
EXIT
No comments:
Post a Comment