4

I have batch file which calls multiple batch files within itself. I need this file to run biweekly (Friday's 10 A.M) when a file drops in a specific path.

I checked the Windows task scheduler but it doesn't have biweekly option. I think we can use the trigger option (to fire when the file drops in the path) to start this batch file but not sure how to do it.

2 Answers 2

3

In the Task Scheduler, if you set the schedule to Weekly you can then set "Recur every:" to 2. Tick the Friday box only, and set the Start time to 10:00:00.

As for detecting when a file is dropped, I don't think you can from there because it's only looking for system events.

4
  • This does not work... at least not anymore. Instead, it causes scheduled tasks to run every week. For example: a task with these settings and that task's run history. These screenshots were taken on Server 2019 but if you do a google search you'll see people reporting the problem as far back as version 1703 (non-server). Anecdotally, this only changed in the last 2 months or so for me.
    – TylerH
    Commented Jun 28, 2021 at 13:52
  • The logic it seems to be following now is "the run every week checkbox is checked, so run it every week. Re-run it every two weeks, too, since that recurrence is set." Thinking about it, that makes a lot more sense than having it run once and then only occur every other two weeks... so I'm currently convinced the method in the answer only ever worked due to a bug.
    – TylerH
    Commented Jun 28, 2021 at 13:53
  • Wow. You'd hope they would have added different controls for the change of behaviour rather than "fix" something that has been relied on working in the wild for so many years, but hey. Good spot anyway, thanks for the update @TylerH
    – randomsock
    Commented Jun 29, 2021 at 21:36
  • I have replaced the task in my earlier screenshot with a 'run daily' task set to repeat every 14 days... that change was made on Monday, and as of Tuesday it hadn't run again, so there's hope for a workaround that way, at least. If it runs prematurely like the weekly task option, I'll try to remember to come back here and give an update.
    – TylerH
    Commented Jun 29, 2021 at 22:03
1

The that came-up to me the /MO switch:

SCHTASKS /Create /SC weekly /D FRI /MO 2 /TN THE_TASK_TM /ST 10:00 /TR c:\some.bat 

with it and /sc weekly you can point the number of the weeks you want. may be there's an easier way but I need to think a little bit.

Edit - I was wrong./MO it the interval so you can leave it to 2 - https://technet.microsoft.com/en-us/library/cc725744.aspx search for "every other week" to hit the correct example.

Other ways are to use the scheduled tasks UI in the control panel or to pass an XML to the schtasks similar to this (edit the things you need) :

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2015-04-24T18:41:41.2112185</Date>
    <Author>computer\user</Author>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2015-04-24T18:40:56.2090861</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByWeek>
        <DaysOfWeek>
          <Friday/>
        </DaysOfWeek>
        <WeeksInterval>2</WeeksInterval>
      </ScheduleByWeek>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>computer\user</UserId>
      <LogonType>InteractiveToken</LogonType>
      <RunLevel>LeastPrivilege</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <Duration>PT10M</Duration>
      <WaitTimeout>PT1H</WaitTimeout>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>the_bat.bat</Command>
      <Arguments>x</Arguments>
      <WorkingDirectory>c:\</WorkingDirectory>
    </Exec>
  </Actions>
</Task>

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