What can I do, if I want to schedule a task on ,for example, fifth day in month, but not during the weekend. Example: if fifth day is saturday, so task will be scheduled on monday.

Thank you for answers.

  • 1
    If you do not want to schedule the task on saturday, because the pc is offline, just check: run as soon as possible if a schedule was missed. – LPChip Mar 23 '18 at 12:47
  • Actually, this task will be working on server so I thing your solution may not works because the server is always online. – kubo Mar 23 '18 at 13:30
  • check if the day is on weekend and schedule a one-time event next Monday – phuclv Mar 23 '18 at 13:51

Below is a solution I've used in the past for a similar task that I modified a little to potentially help with your need. The trick is to have the Task Scheduler execute a batch script and have the batch script that's executed have the logic in it to do the conditional checks to run or not.

You can use CALL or START to execute executable files (an app), another batch script, execute PowerShell scripts, and other types of scripts. Sometimes the Task Scheduler scheduling isn't robust enough for special scheduling needs as in this case.

Essentially this solution will. . .

  • Trigger it to run every month on the 5th, 6th, and 7th so if Saturday is the 5th, Sunday is the 6th, then Monday will be the 7th but even if Sunday is the 5th or 6th it'll still run on Monday the 6th or 7th

    enter image description here

  • Incorporate a batch script that will run some initial conditional logic that will check for the day of the week and take action based on these conditions whether or not to create a file with the word Run in it, but if it already has been created with Run for that month then EXIT

Batch Script

Note: The only thing you really need to adjust with this is to use the correct path in the SET RunFile=C:\SomeFolder\SomePath\ portion to make it the correct folder or UNC path to create the run file, etc. Then just make the <Rest of logic needed > just execute or run whatever logic or script the Task Scheduler is running now.


::: -- Set date variables for conditional logic for the current date and day of week
FOR /F "TOKENS=1 DELIMS=." %%A IN ('WMIC OS GET LocalDateTime ^| FIND "."') DO SET rundt=%%~A
SET rundt=%rundt:~0,6%
FOR /F "TOKENS=1 DELIMS=." %%A IN ('WMIC PATH Win32_LocalTime GET DayOfWeek ^| FINDSTR /R [0-9]') DO SET DOW=%%~A

::: -- If the day today is 6 for Saturday or 7 for Sunday then EXIT

::: -- Set the run file location to create a file with "run" in it if the day is correct
SET RunFile=C:\SomeFolder\SomePath\%rundt%.run

::: -- If "Run" already found in "~\<YYYYMM>.run" file then do not run because it already has this month
FINDSTR /I Run "%RunFile%"

ECHO Run>"%RunFile%"
<Rest of logic needed    >
<CALL C:\folder\app.exe  >


Further Resources

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.