I want to built a logic for my windows batch script that it should only run between 7:00 and 23:00 daily.
I have added logic like below
SET "Offertime=%time:~0,2%"
IF %Offertime% leq 23 set "RunOffer=True"
IF %Offertime% geq 07 set "RunOffer=True"
IF "%RunOffer%"=="True" (
CALL "C:\TCC_Touch_Point_Folder\bin\Windows\core\Rcap_Offer_Cal.bat"
)
exit
But this is not working, can anyone please let me know where I am going wrong in this ? or any better way to achieve this solution?
Your condition is always true because 'Offertime' is either less/equal than 23 or greater/equal than 7. This would work:
SET hour=%time:~0,2%
SET shouldrun=True
IF %hour% geq 23 SET shouldrun=False
IF %hour% leq 6 SET shouldrun=False
IF "%shouldrun%"=="True" (
CALL "C:\TCC_Touch_Point_Folder\bin\Windows\core\Rcap_Offer_Cal.bat"
)
If you're looking to run a bat file at a specific time, the usual way is to schedule it using windows task scheduler.
or
Then create a task setting up the time to run.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.