Strategist
Strategist

Reputation: 43

How to schedule a batch script file biweekly?

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.

Upvotes: 4

Views: 5248

Answers (2)

npocmaka
npocmaka

Reputation: 57252

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>

Upvotes: 1

randomsock
randomsock

Reputation: 1014

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.

Upvotes: 3

Related Questions