Endoro wrote:I'm not really sure about your needs- but you can try this.
It does:
- get the current Julian Day
- get the last stored Julian Day from a .sav file, build one if it not exists
- check the difference between today and the stored Julian Day
- if the difference is greater than 29 it might start your task if you put the code in and the current Julian Day is stored
- the Julian Day function is from here.Code: Select all
@echo off&setlocal
set "fsave=%~dpn0.sav"
call:JDNtoday cJDN
call:getsaveJDN sJDN
if not defined sJDN goto:saveJDN
set /a days=%cJDN%-%sJDN%
echo(%days% day(s^) have passed.
if %days% gtr 29 (
rem start task B here
echo(starting task B now ...
rem store the new date in %~dpn0.sav
call:saveJDN
)
goto:eof
:saveJDN
>"%fsave%" echo(%cJDN%&& (echo(Date saved & goto:eof) || echo ERROR date NOT in "%fsave%" saved & goto:eof
goto:eof
:getsaveJDN
setlocal
if exist "%fsave%" for /f "usebackq" %%i in ("%fsave%") do set "JDN=%%i"
endlocal& set "%1=%JDN%"
exit /b
:JDNtoday
setlocal
for /f "tokens=2*" %%a in ('reg query "HKCU\Control Panel\International" /v sShortDate^|find "REG_SZ"') do set "ssShortDate=%%b"
reg add "HKCU\Control Panel\International" /f /v sShortDate /d "dd MM yyyy" >nul
set "cdate=%date%"
reg add "HKCU\Control Panel\International" /f /v sShortDate /d "%ssShortDate%" >nul
for /f "tokens=1-3" %%i in ("%cdate%") do set "day=0%%i"&set "month=0%%j"&set "year=%%k"
set "day=%day:~-2%"
set "month=%month:~-2%"
call:DateToJDN %day%.%month%.%year% JDN
endlocal& set "%1=%JDN%"
exit /b
:DateToJDN dd.mm.yyyy jdn=
setlocal
set date=%1
set /A yy=%date:~-4%, mm=1%date:~-7,2% %% 100, dd=1%date:~-10,2% %% 100
set /A a=mm-14, jdn=(1461*(yy+4800+a/12))/4+(367*(mm-2-12*(a/12)))/12-(3*((yy+4900+a/12)/100))/4+dd-32075
endlocal & set %2=%jdn%
exit /B
endlocal
Ok, so as intermediate batch coder I'm seeing instead of check.bat running the program it self, your code triggers the Task B and all I need to do is re-create Task B and your code starts over to new Task B beginning date and thus comparisons and action or no action
Is that correct?
I know you put remarks in code but can you walk me through it a little please?
Also can or are we deleting the Check.sav after Check.bat has done the coding to detect difference and run task B which runs program?
Thanks you are so helpful and I really like seeing advanced batch code to learn from
@Squashman
Thanks for coming back I still wish for it to be automated so user is free from doing anything manually. I actually had a .xml file that set that setting but don't want to have any rogue files in this endevour, just one .cmd file with everything
My initial desires we're to indeed query the scheduled task or do queries in general and your idea of NEXT RUN TIME is an great idea!
Here is the code to create and query a task schedule which shows exact time/date Task B will run!
Code: Select all
schtasks /create /tn "TaskB" /tr "%SystemDrive%\Program.exe" /sc daily /mo 30 /ru "" /f >NUL
Code: Select all
schtasks /query /tn "TaskB" 2>NUL | FINDSTR "TaskB"
Let me see if I can redefine the logic for this batch not so much for you guys but to talk out loud for myself so I can better understand
Code: Select all
1. Check.bat file contains code to track dates in a universal region way and in comparing them, if past time/date Task B runs program.exe then check.bat just exits
2. After that Task B is re-created so new date will be available for comparison and check.bat code deletes check.sav and does new check.sav