随笔 - 911  文章 - 5  评论 - 94  阅读 - 243万

schtasks---at

通过schtasks和at命令建立的任务计划都会在后台运行,不会显示运行窗口

新建计划任务,每天16:53运行notepad.exe,计划任务名为“nn”
schtasks /create /sc daily /tn "nn" /tr notepad.exe /st 16:53

/f 强制覆盖已有任务,不提示

/z 标记为运行完成后删除任务

/sc once /sd 2081/01/01

 

新建计划任务,以用户ly(密码:cmr)最高级别权限运行 D:\m.bat ,任务名称为“nn2”,每周一晚上20:20运行
schtasks /Create /RU liuyan /RP cmr /tN "nn2" /TR "D:\m.bat" /SC WEEKLY /D MON /ST 20:20 /RL HIGHEST

 

schtasks /query /tn "nn"

schtasks /query |Select-String "nn"

 

schtasks /delete /tn "nn" /f

 

修改计划任务属性(运行频率无法修改:/sc)
schtasks /change /tn "nn" /tr notepad.exe /st 09:43 /s localhost

 

 当在非域环境下使用 schtasks /create /s ServerName /tn MyApp 创建任务计划时,会出现如下警告:

The Scheduled task "MyApp" has been created, but may not run because the account information could not be set.

原因:此警告表示远程域无法对 /u 参数指定的帐户进行身份验证。在此种情况下,远程域无法对用户帐户进行身份验证,因为本地计算机不是远程计算机域信任的域的成员。如果发生这种情况,任务作业就会出现在计划任务的列表中,但任务实际上为空,所以不会运行。

 在Windows Server 2008 R2(中文版)下运行 schtasks /query 时,会提示”无法加载资源列表“,需要更改活动代码页编号:

 chcp 437 表示更改为英语, chcp 936表示更改为中文,默认是 936.

如果将 chcp 437单独放在脚本中的一行,则后面的命令在运行的时候依然会使用 chcp 936。这时需要将 chcp 和将要使用的命令写在同一行,如下:

 cmd /c "chcp 437 >null && schtasks /query" |select-string $TaskName  -Encoding default

 

/SC schedule Specifies the schedule frequency.
Valid schedule types: MINUTE, HOURLY, DAILY, WEEKLY,
MONTHLY, ONCE, ONSTART, ONLOGON, ONIDLE, ONEVENT.

 

/D days Specifies the day of the week to run the task. Valid
values: MON, TUE, WED, THU, FRI, SAT, SUN and for
MONTHLY schedules 1 - 31 (days of the month).
Wildcard "*" specifies all days.

 

/M months Specifies month(s) of the year. Defaults to the first
day of the month. Valid values: JAN, FEB, MAR, APR,
MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC. Wildcard "*"
specifies all months.

posted on   momingliu11  阅读(1391)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
< 2013年5月 >
28 29 30 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 1
2 3 4 5 6 7 8

点击右上角即可分享
微信分享提示