Abaixo está uma solução que usei no passado para uma tarefa semelhante que modifiquei um pouco para ajudar potencialmente com sua necessidade. O truque é fazer com que o Agendador de Tarefas execute um script em lote e que o script em lote que é executado tenha a lógica para executar as verificações condicionais ou não.
Você pode usar CALL ou START para executar arquivos executáveis (um aplicativo), outro script em lote, execute scripts do PowerShell e outros tipos de scripts. Às vezes, o agendamento do Agendador de Tarefas não é robusto o suficiente para necessidades especiais de agendamento, como neste caso.
Essentially this solution will. . .
Trigger it to run every month on the
5th,6th, and7thso if Saturday is the5th, Sunday is the6th, then Monday will be the7thbut even if Sunday is the5thor6thit'll still run on Monday the6thor7thIncorporate 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
Runin it, but if it already has been created withRunfor that month thenEXIT
Script em lote
Nota: A única coisa que você realmente precisa ajustar é usar o caminho correto na porção SET RunFile=C:\SomeFolder\SomePath\ para torná-la a pasta correta ou o caminho UNC para criar a execução Então, basta fazer o <Rest of logic needed > apenas executar ou executar qualquer lógica ou script que o Agendador de Tarefas esteja executando agora.
@ECHO ON
::: -- 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
IF %DOW%==6 EXIT
IF %DOW%==7 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%"
IF ERRORLEVEL 1 (GOTO :Run) ELSE (EXIT)
:Run
ECHO Run>"%RunFile%"
<Rest of logic needed >
<CALL C:\folder\app.exe >
EXIT
