windows的计划任务

可以做什么

  • 自动执行定时任务
    • 每天备份xx文件
  • 在指定条件执行特定任务
    • 在系统空闲时做xx
    • 在用户登录后做xx

如何使用

win+R,输入taskschd.msc

新建任务列表

扩展

可以使用SCHTASKS来完成与GUI操作一样的命令

示例

登录时,自动启动everything。

导出后的xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Description>运行everything</Description>
</RegistrationInfo>
<Triggers>
<LogonTrigger>
<Enabled>true</Enabled>
</LogonTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>ff-PC\ff</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>P3D</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Program_tools\Everything\Everything.exe</Command>
<Arguments>-startup</Arguments>
</Exec>
</Actions>
</Task>

备份脚本

RunBackup.bat

1
2
3
4
5
6
@echo off

@SET EXEPATH="C:\Program Files\7-Zip\7z.exe"
@SET PROJECTPATH="E:\Project\Blog"

%EXEPATH% a -tzip "G:\BlogBackup\%date:~0,4%-%date:~5,2%-%date:~8,2%\EdiBlog.zip" %PROJECTPATH%

参考