简体   繁体   English

计划任务未在 windows 中触发

[英]Scheduled task not getting triggered in windows

I would like to run the below python script every 5 mins on the daily basis:我想每天每 5 分钟运行一次以下 python 脚本:

C:\Users\******\Desktop\task\task.py C:\用户\******\桌面\任务\task.py

I created the below task:我创建了以下任务:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2022-04-18T16:12:35.5603012</Date>
    <Author>DESKTOP-*****\*****</Author>
    <URI>\tast test</URI>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <Repetition>
        <Interval>PT5M</Interval>
        <StopAtDurationEnd>false</StopAtDurationEnd>
      </Repetition>
      <StartBoundary>2022-04-18T00:00:00</StartBoundary>
      <EndBoundary>2023-04-20T16:06:26</EndBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>******</UserId>
      <LogonType>S4U</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>true</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
    <DeleteExpiredTaskAfter>P30D</DeleteExpiredTaskAfter>
    <Priority>7</Priority>
    <RestartOnFailure>
      <Interval>PT1M</Interval>
      <Count>3</Count>
    </RestartOnFailure>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Users\*****\AppData\Local\Programs\Python\Python39\python.exe</Command>
      <Arguments>task.py</Arguments>
      <WorkingDirectory>C:\Users\****\Desktop\task</WorkingDirectory>
    </Exec>
  </Actions>
</Task>

The python script is not executed every 5 mins, but the Next runtime gets changed and the last run time still shows as python 脚本不是每 5 分钟执行一次,但是 Next runtime 被更改并且最后一次运行时间仍然显示为在此处输入图像描述

As stated in the comment from @Daemon, when setting up a scheduled task action, the command field should contain the path to the executable (eg C:\Users\*****\AppData\Local\Programs\Python\Python39\python.exe ) and the arguments field should contain the full path to the file you want to run, which in this case should presumably be C:\Users\****\Desktop\task\task.py .正如@Daemon 的评论所述,在设置计划任务操作时,命令字段应包含可执行文件的路径(例如C:\Users\*****\AppData\Local\Programs\Python\Python39\python.exe ) 和 arguments 字段应包含您要运行的文件的完整路径,在本例中应该是C:\Users\****\Desktop\task\task.py

So I would expect the action section to look like所以我希望动作部分看起来像

<Actions Context="Author">
  <Exec>
    <Command>C:\Users\*****\Python39\python.exe</Command>
    <Arguments>C:\Users\****\Desktop\task\task.py</Arguments>
  </Exec>
</Actions>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM