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 2013-05-29 16:53  momingliu11  阅读(1371)  评论(0编辑  收藏  举报