windows 从命令行使用schtasks,什么参数将计算机从睡眠中唤醒并执行任务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/497945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using schtasks from the command line, what parameter will wake the computer from sleep and execute the task
提问by thetreat
The option exists in the UI, but not in the help displayed in the command line.
该选项存在于 UI 中,但不在命令行中显示的帮助中。
回答by NicJ
Are you creating a new task via the schtasks.exe
command line, or updating an existing task?
您是通过schtasks.exe
命令行创建新任务还是更新现有任务?
On Vista, schtasks.exe
has an /xml
option for both /create
and /query
. With this XML encoding of the task, you can see the WakeToRun
node can be set for waking the computer from sleep to run the task:
在 Vista 上,schtasks.exe
可以/xml
选择/create
和/query
. 使用此任务的 XML 编码,您可以看到WakeToRun
可以设置节点以将计算机从睡眠中唤醒以运行任务:
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
...
</RegistrationInfo>
<Triggers />
<Principals>
...
</Principals>
<Settings>
...
<WakeToRun>true</WakeToRun>
...
</Settings>
<Actions Context="Author">
<Exec>
<Command>myprogram.exe</Command>
</Exec>
</Actions>
</Task>
If you need to create a task from the command line that wakes the computer, you could export the basics of the task to XML, modify this XML to add WakeToRun
, then re-import this XML definition. You can do this two ways:
如果您需要从唤醒计算机的命令行创建任务,您可以将任务的基础知识导出到 XML,修改此 XML 以添加WakeToRun
,然后重新导入此 XML 定义。您可以通过两种方式执行此操作:
In the Task Scheduler UI, select "Wake the computer to run this task", right-click on the task and
Export...
to XML. You can then re-import this file on another machine (see below), and Wake-To-Run will be set. or,Via the command line, create a task with the basics set (action, time, etc). Then, export the XML, programatically add the
WakeToRun
node (via XSLT or search/replace), then re-import this updated XML:schtasks.exe /create /tn /xml MyTask.xml /f
在任务计划程序 UI 中,选择“唤醒计算机以运行此任务”,右键单击该任务并
Export...
转到 XML。然后你可以在另一台机器上重新导入这个文件(见下文),Wake-To-Run 将被设置。或者,通过命令行,使用基本设置(动作、时间等)创建任务。然后,导出 XML,以编程方式添加
WakeToRun
节点(通过 XSLT 或搜索/替换),然后重新导入此更新的 XML:schtasks.exe /create /tn /xml MyTask.xml /f
回答by BtilEntrails
In step 2 the command line; schtasks.exe /create /tn /xml MyTask.xml /f
This may kick an error that says;
Invalid syntax. Mandatory option 'tn' is missing.
在第 2 步中的命令行;schtasks.exe /create /tn /xml MyTask.xml /f
这可能会引发一个错误:无效的语法。缺少必需选项“tn”。
/tn
needs a name. This should be
/tn
需要一个名字。这应该是
schtasks.exe /create /tn MyTask /xml "C:\MyTask.xml" /f
And if you have or want a space in the name, you can use;
如果您在名称中有或想要一个空格,则可以使用;
schtasks.exe /create /tn "My Task With Spaces" /xml "C:\My Task With Spaces.xml" /f
Hope this helps...
希望这可以帮助...