1

On Windows 10 I created a scheduled task to make a snapshot of C:\ each hour from 8:00 AM to 5:00 PM.
Works fine as long as the computer is running or stopped (not sleeping).

Problem : if the computer fall asleep during 8 AM - 5 PM, the scheduled task is fired when the computer wake up.
For example the computer fall asleep at 4:45 PM. It wake up at 9:15 PM, a snapshot is done, which is not desired.

How can I prevent the scheduled task to do its job outside the desired hours?

The task is exported there:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2019-01-01T00:00:00.00</Date>
    <Author>Author</Author>
    <URI>\VSS</URI>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <Repetition>
        <Interval>PT1H</Interval>
        <Duration>PT8H</Duration>
        <StopAtDurationEnd>false</StopAtDurationEnd>
      </Repetition>
      <StartBoundary>2019-01-01T09:00:00</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByWeek>
        <DaysOfWeek>
          <Monday />
          <Tuesday />
          <Wednesday />
          <Thursday />
          <Friday />
        </DaysOfWeek>
        <WeeksInterval>1</WeeksInterval>
      </ScheduleByWeek>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>S-1-5-18</UserId>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>false</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
    <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT10M</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Windows\System32\wbem\WMIC.exe</Command>
      <Arguments>shadowcopy call create Volume=C:\</Arguments>
    </Exec>
  </Actions>
</Task>
1
  • Have you tried to set the DeleteExpiredTaskAfter value?
    – Robert
    Commented Jan 8, 2020 at 13:34

3 Answers 3

2
+100

it would be possible using PowerShell as the intermediary of executing the WMIC command.

Set the scheduled task to execute the powershell executable "powershell.exe" and pass the path to the location of the powershell script ".PS1" file as the argument.

Please see the below script that will pull the current time and execute the WMIC command if the time falls within the hours that you specify:

$StartHour = 8
$EndHour = 17

$DateTimeNow = Get-Date
If($DateTimeNow.Hour -ge $StartHour -and $DateTimeNow.Hour -le $EndHour){
    C:\Windows\System32\wbem\WMIC.exe shadowcopy call create Volume=C:\
}
Else{
    Exit
}

You can change the hours using the variables $StartHour & $EndHour, I would suggest putting the hours in a 24 hour format.

Hopefully this helps!

1

On the settings tab of the task in Task Scheduler there is an option to "Run task as soon as possible after a scheduled task start is missed". Try unchecking that.

1
  • Already done. To be clear, I updated the question with an export of the task definition. Commented Dec 28, 2019 at 19:05
1

This looks like an issue which has been reported several times, and, has yet, not been provided with a resolution on MS related forums.

In case you have not tried this before, attempt this workaround, if you think is suitable to your purpose. The explanation (for the workaround) makes sense. Keep a close eye on the drawbacks listed.

How to prevent scheduled tasks from running as soon as computer wakes up?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .