你想让你的电脑(PC sleep)在每天的特定时间休眠或关闭吗?或者,也许您希望您的 PC 在每次启动时或 12 点时开始播放励志视频?如果您希望通过某种方式对您的 PC 进行编程以在特定时间执行特定操作,您应该阅读这篇文章,因为我们将介绍任务计划程序的(Task Scheduler's)一些高级功能:创建高级任务、设置其触发器、操作和安全选项. 当您想要控制系统及其正在运行的任务时,它们非常强大。因此,请为广泛的选择做好准备,这些选择允许您设置与计划任务相关的所有可能细节。让我们开始吧:
注意:(NOTE:)本指南适用于Windows 10、Windows 7 和Windows 8.1。为了说明您可以使用任务计划程序(Task Scheduler)执行的操作,我们将创建一个高级任务,该任务每天晚上 11:00 关闭 PC。
如何在Windows(Windows)中创建高级任务
首先打开任务计划程序(Task Scheduler)。如果您不知道如何执行此操作,您应该阅读这篇文章:在Windows中启动(Windows)任务计划程序(Task Scheduler)的 9 种方法(所有版本)。如果您也没有时间阅读该指南,请知道在任何Windows 版本中打开(Windows version)任务计划程序(Task Scheduler)的快速方法是使用搜索:搜索“任务计划程序”("task scheduler")并单击或点击相应的搜索结果(search result)。
此外,如果您以前从未使用过任务计划程序(Task Scheduler),那么熟悉一下它可能是个好主意。为此,请阅读以下内容:如何使用任务计划程序(Task Scheduler)创建基本任务,分 5 个步骤。
现在让我们开始做事:要创建新任务,请在“任务计划程序(Task Scheduler)”窗口中,转到“操作(Actions)”面板,然后在其右侧单击或点击(click or tap) “创建任务”。("Create Task.")
启动的向导允许您设置有关新任务的每个细节,从其名称开始,然后继续设置一个或多个触发器、操作、建立运行任务的条件等。
让我们看看它是如何工作的:
如何设置任务的名称、描述和安全选项(description & security options)
“创建任务”("Create Task")向导的第一个选项卡名为“常规”,(General,)您可以在此处设置任务名称及其描述。因为我们想要创建一个每天晚上关闭 PC 的任务,所以我们将其命名为“晚上睡觉”。("Sleep at night.")
常规(General)选项卡还允许您配置与用于运行您正在创建的任务的用户帐户和权限(user account and privileges)相关的其他“安全选项” 。("Security options")默认情况下,用于运行任务的用户帐户(user account)是您用于创建任务的用户帐户。如果您想在运行任务时使用另一个用户帐户(user account),请单击或点击“更改用户或组”("Change User or Group")按钮并选择另一个。
您可以选择仅在用户登录时运行任务,或者即使他或她未登录也运行它。在我们的例子中,用户是否登录并不重要,因为我们想要创建一个关闭计算机的任务。
如果您的任务需要管理员权限,请不要忘记选中“以最高权限运行”("Run with highest privileges")复选框。然后,如果您不希望任务可见,请选中隐藏选项。(Hidden)这意味着当任务开始或结束时,登录的用户不会收到通知。我们不打算这样做,因为我们希望用户能够在他或她想在晚上进一步使用 PC 时停止关机程序。🙂
这就是关于一般设置的全部内容。让我们转到触发器(Triggers)选项卡。
如何在任务计划程序中设置任务的触发器(Task Scheduler)
触发器(Triggers)选项卡允许您设置多个触发器。要添加新触发器,请单击或点击窗口底部的“新建”(New)按钮。
第一个触发设置(trigger setting)是选择何时开始任务。单击(Click)或点击“开始任务”("Begin the task")下拉框,然后选择可用选项之一。
对于我们的关闭任务,我们必须选择“按计划”("On a schedule")并将任务设置为每天(Daily)晚上 11 点运行。
我们已经在本教程中讨论了其他一些可用的触发器:如何使用任务计划程序(Task Scheduler)创建基本任务,分 5 个步骤。但是,与创建基本任务(Create Basic Task)向导相比,还有一些额外的触发器,例如:"At task creation/modification," “在连接到用户会话时”、“在与用户会话断开时”、“在工作站锁定时”("On connection to user session," "On disconnect from user session," "On workstation lock")和“在工作站解锁。” ("On workstation unlock.")根据您选择的选项,您需要在“设置”(Settings)窗格中设置不同的内容,但无论您选择什么触发器,可用的高级设置都保持不变。(Advanced settings)
对于名为“On connection to user session”和“On disconnect from user session”的触发器,您可以进行以下设置:
- 如果“连接到用户会话”(connection to user session")是指任何用户或特定用户,则建立。对于后者,默认为当前用户。但是,您可以单击或点击更改用户(Change User)并选择其他用户。
- 如果连接(connection)是指来自远程或本地计算机的连接,则建立。
对于“在工作站锁定”("On workstation lock")和“在工作站解锁”("On workstation unlock")触发器,您只需设置它是否指代任何用户或特定用户。默认情况下,特定用户是当前用户。您可以单击或点击“更改用户”("Change User")以选择另一个用户帐户。
如何设置任务触发器的高级设置
所有触发器的可用高级设置(Advanced settings)相同。对于每个可用选项,您必须首先选中相应的框以查看类似选项的列表。您可以进行以下设置:
- 将任务延迟一定时间:30秒、1分钟、15分钟、30分钟、1小时、8小时或1天;
- 选择重复任务的时间间隔(time interval)(5、10、15、30 分钟或 1 小时)和重复的持续时间(15 或 30 分钟、1 或 12 小时、1 天或无限期);
- 如果您的任务由于某种原因运行时间可能比您指定的时间长,您可以选择让它自动停止;
- 您可以设置激活和到期日期(activation and expiration date)和时间。这意味着满足您指定的触发器时您的任务将运行的日期;
- 您可以启用或禁用该任务。
对于我们正在创建的日常PC 关机(PC shutdown)任务,我们不需要任何这些高级设置:我们所要做的就是确保该任务已启用(Enabled)。
完成此触发器的设置后,单击或点击确定。(OK)您的新触发器显示在触发器列表中。您可以创建一个新触发器或选择一个已创建的触发器来编辑或删除它。
如何在任务计划程序中设置任务的操作(Task Scheduler)
您可以将多个操作分配给一个任务。为此,请转到“操作(Actions)”选项卡并单击或点击“新建”(New)按钮。
(Choose one)通过单击或点击“操作”(Action)下拉框,选择任务必须执行的操作之一。您可以选择:启动程序、发送电子邮件或显示消息。
如果您选择启动程序,请单击或点击浏览(Browse)按钮以选择要启动的应用程序。然后,如果需要,填写名为Arguments和Start in的可选字段。
对于我们的关机任务,我们必须选择“启动程序”。("Start a program.")然后,我们必须在Program/script字段中输入关闭(shutdown)命令。为了使该命令起作用,我们还必须输入正确的参数,因此,在“添加参数”("Add arguments")字段中,我们将输入-s和-f。-s参数告诉计算机我们希望它关闭,而不是重新启动或睡眠,而-f参数(-f)告诉它我们希望强制应用程序在关机时关闭。
注意:(NOTE:)如果您想要的不是运行程序而是发送电子邮件,则必须填写From和To字段,设置主题,编写电子邮件文本(email text),添加任何附件并指定SMTP 服务器(SMTP server)(在属性中找到您的电子邮件帐户(email account))。要显示消息,您必须指定标题和消息。请记住(Remember),在Windows 10和 8.1 中,“发送电子邮件”("Send an e-mail")和“显示消息”("Display a message")任务已被弃用 - 这意味着这些操作无法在这些Windows版本中执行。
正如我们之前提到的,您可以为一个任务创建多个操作。例如,您可以创建一个运行磁盘清理(Disk Cleanup)的任务,然后才关闭您的计算机。您可以通过单击或点击操作列表右侧的按钮来更改操作的顺序。
要修改操作,请选择它并单击或点击编辑(Edit)。要删除它,请单击或点按删除(Delete)。
如何在任务计划程序(Task Scheduler)中设置任务条件
除了触发器之外,您还可以根据已过去的空闲时间来指定任务何时运行的几个条件,计算机是使用交流电源(AC power)还是特定网络可用。要设置它们,请单击或点击条件(Conditions)选项卡。请注意,如果您想像我们一样创建关闭任务,则无需配置任何这些条件。
如果您希望任务不干扰您的工作,您可以将其设置为仅在计算机空闲时运行。选中“仅在计算机空闲时启动任务”("Start the task only if the computer is idle for")框,然后选择一个可用时间段。从您设置任务开始的时间开始,您可以选择等待计算机进入空闲状态一段时间,也可以选择“不等待空闲”。("Don't wait for idle.")当计算机不再处于空闲状态时,您可以决定停止任务或在空闲状态恢复时重新启动它。例如,当您知道您的任务可能需要许多系统资源才能运行时,这些空闲选项很有用。将它们设置为在您的PC 或设备时运行(PC or device)is idle 意味着您不会因程序运行缓慢而烦恼,因为此任务会占用您计算机的大部分资源。
由于任务可能会运行很长时间,因此任务计划程序(Task Scheduler)允许您为任务设置条件,使其仅在计算机使用交流电源(AC power)时启动,并在切换到电池电源时停止任务。如果您的计算机处于睡眠模式并且是运行任务的时间,您可以将计算机设置为唤醒并运行任务。
如果您知道运行任务需要特定的网络连接,请选中(network connection)“仅在以下网络连接可用时启动”("Start only if the following network connection is available")框并选择您感兴趣的连接。
如何设置任务的失败行为(failure behavior)
任务计划程序(Task Scheduler)允许您进行在特殊情况下派上用场的设置,例如任务失败或正在运行的任务在请求时没有结束。转到“创建任务(Create Task)”向导中的“设置”(Settings)选项卡。
您可以进行以下设置:
- 允许任务按需运行。否则,它仅在满足触发器和条件时运行。
- 如果任务基于错过的计划,您可以将任务设置为尽快运行。
- 对于任务失败的情况,您可以将其设置为每 1、5、10、15、30 分钟或 1-2 小时重新启动一次。可以在您设置的时间内尝试重新启动。
- 如果您认为您的任务出现问题,并且运行时间超过 1、2、4、8、12 小时或 1-2 天,您可以将其设置为停止。
- 如果任务未计划再次运行,您可以将计算机设置为在 30、90、180、365 天后或立即自动删除该任务。
- 如果任务已经在运行并且需要再次运行,您可以选择以下选项之一:“不启动新实例”("Do not start a new instance")(任务的第一个实例继续运行)、“运行新实例并行”("Run a new instance in parallel")(第一个任务实例(task instance)继续运行,新的任务实例(task instance)也开始),“排队一个新的实例”("Queue a new instance")(新的任务实例在第一个任务实例(task instance)完成后运行),和“停止现有的实例”("Stop the existing instance")(第一个任务实例(task instance)停止,并启动新的任务实例(task instance))。
当您根据需要设置好所有内容后,按OK按钮,任务会立即创建,您可以随时在任务计划程序库(Task Scheduler Library)中找到它。
您是否使用任务计划程序(Task Scheduler)来创建高级任务?
如您所见,任务计划程序(Task Scheduler)提供了大量设置,可帮助您创建大量高级任务。虽然一开始并非所有选项都易于理解,但通过仔细阅读本文并自行尝试,您应该很快掌握它并获得对计算机的更多控制权。如果您对任务计划程序(Task Scheduler)有任何疑问,请随时在下面的评论部分中提问。
How to create advanced tasks with the Task Scheduler
Dо you want to make your PC sleеp or shut down at a particular time every day? Or maybe yоu want your PC to start playing a motivationаl vіdeo each time you start it or when it is 12 o'cloсk? If you wished for a way to program your PC to do certain things at сertain tіmes, you should read this article, as we are goіng to cover some of Task Scheduler's advanced features: creating advanced tasks, setting up their triggers, actions and security options. They are powerful when you want to be in control of your system and the tasks it is running. So be prepared for an extensive range of choices which allow you to set up every possible detail related to scheduled tasks. Let's get started:
NOTE: This guide applies to Windows 10, Windows 7 and Windows 8.1. To illustrate the things you can do with Task Scheduler, we are going to create an advanced task that shuts down the PC every day at 11:00 PM.
How to create an advanced task in Windows
Start by opening the Task Scheduler. If you do not know how to do this, you should read this article: 9 ways to start the Task Scheduler in Windows (all versions). If you do not have time to read that guide too, know that a fast way to open the Task Scheduler, in any Windows version, is to use the search: search for "task scheduler" and click or tap the appropriate search result.
Also, if you have never worked with the Task Scheduler before, it might be a good idea to familiarize yourself a bit with it. For that, read this: How to create basic tasks with Task Scheduler, in 5 steps.
Now let's get to business: to create a new task, in the Task Scheduler window, go to the Actions panel and, on its right side, click or tap "Create Task."
The wizard that starts lets you set up every detail about your new task, starting with its name and continuing with setting one or multiple triggers, actions, establishing conditions for running the task and so on.
Let's see how it works:
How to set the name, description & security options of a task
The first tab of the "Create Task" wizard is named General, and it is the place where you can set the name of the task and its description. Because we want to create a task that shuts down our PC every night, we are going to name it "Sleep at night."
The General tab also lets you configure additional "Security options" related to the user account and privileges used to run the task that you are creating. By default, the user account that is used for running the task is the one you use for creating the task. If you want to make use of another user account when running the task, click or tap the "Change User or Group" button and select another.
You can choose to run the task only when the user is logged on or run it even if he or she is not logged on. In our case, it does not matter if the user is logged on or not, as we want to create a task that shuts down the computer.
If your task needs administrator permissions, do not forget to check the "Run with highest privileges" checkbox. Then, check the Hidden option if you do not want the task to be visible. This means that the logged on user is not notified when the task is started or ended. We are not going to do that because we want the user to be able to stop the shutdown procedure if he or she wants to use the PC further in the night. 🙂
That is all there is regarding general settings. Let's go to the Triggers tab.
How to set the triggers of a task in Task Scheduler
The Triggers tab lets you set multiple triggers. To add a new trigger, click or tap the New button, from the bottom of the window.
The first trigger setting is to select when to begin the task. Click or tap the "Begin the task" drop-down box and choose one of the available options.
For our shutdown task, we must choose "On a schedule" and set the task to run Daily, at 11 PM.
We have already talked about some of the other triggers available, in this tutorial: How to create basic tasks with Task Scheduler, in 5 steps. However, there are a few additional triggers compared to the Create Basic Task wizard, such as: "At task creation/modification," "On connection to user session," "On disconnect from user session," "On workstation lock" and "On workstation unlock." Based on the option you chose, you are required to set different things in the Settings pane, but the Advanced settings that are available remain the same no matter what trigger you choose.
For the triggers named "On connection to user session" and "On disconnect from user session" you can make the following settings:
- Establish if "connection to user session" refers to any user or a specific user. For the latter, the default is the current user. However, you can click or tap Change User and choose another user.
- Establish if connection refers to a connection from a remote or a local computer.
For the "On workstation lock" and "On workstation unlock" triggers you only have to set if this refers to any user or a specific user. By default, the specific user is the current one. You can click or tap "Change User" to select another user account.
How to set the advanced settings for the triggers of a task
The available Advanced settings are the same for all triggers. For each available option, you must first check the corresponding box to see the list of similar choices. You can make the following settings:
- Delay a task for a certain time: 30 seconds, 1 minute, 15 minutes, 30 minutes, 1 hour, 8 hours or 1 day;
- Choose the time interval after which the task is repeated (5, 10, 15, 30 minutes or 1 hour) and the duration of the repeat (15 or 30 minutes, 1 or 12 hours, 1 day or indefinitely);
- If your task, for some reason, might run longer than the period you specify you can choose to have it stopped automatically;
- You can set an activation and expiration date and time. This means the dates between which your task is going to be run when the trigger that you specify is met;
- You can enable or disable the task.
For the daily PC shutdown task that we are creating, we do not need any of these advanced settings: all we have to do is making sure that the task is Enabled.
Click or tap OK when you have finished with the settings for this trigger. Your new trigger is displayed in the list of triggers. You can either create a new one or select an already created trigger to edit it or delete it.
How to set the actions of a task, in Task Scheduler
You can assign multiple actions to a task. To do this, go to the Actions tab and click or tap the New button.
Choose one of the actions that the task must perform by clicking or tapping the Action drop-down box. You can select from: starting a program, sending an e-mail or displaying a message.
If you choose to start a program, click or tap the Browse button to choose the application to be started. Then, if needed, complete the optional fields called Arguments and Start in.
For our shutdown task, we must choose "Start a program." Then, we have to enter the shutdown command in the Program/script field. For this command to work, we also have to input the right arguments so, in the "Add arguments" field we are going to type -s and -f. The -s argument tells the computer that we want it to shut down, not reboot or sleep, and the -f argument tells it that we want to force apps to close at shutdown.
NOTE: If what you want is not to run a program but to send an email, you have to complete the fields From and To, set a subject, write the email text, add any attachments and specify the SMTP server (found in the properties of your email account). For displaying a message, you have to specify the title and the message. Remember that in Windows 10 and 8.1, the "Send an e-mail" and "Display a message" tasks are deprecated - meaning that these actions cannot be performed in these Windows versions.
As we have mentioned previously, you can create multiple actions for a task. For example, you can create a task that runs Disk Cleanup and only then shuts down your computer. You can change the order of the actions by clicking or tapping the buttons found on the right-hand side of the actions list.
To modify an action, select it and click or tap Edit. To remove it, click or tap Delete.
How to set up the task conditions in Task Scheduler
Apart from the trigger, you can specify several conditions for when the task is run based on the idle time that has passed, whether the computer is on AC power or a specific network is available. To set them, click or tap the Conditions tab. Note that if you want to create a shutdown task just like we did, you do not need to configure any of these conditions.
If you want the task not to interfere with your work, you can set it to run only when the computer is idle. Check the box that says "Start the task only if the computer is idle for" and choose one of the available periods. From the time you have set the task to start, you can choose to wait for the computer to switch into an idle state for a certain period or you can select "Don't wait for idle." When the computer is no longer in an idle state, you can decide to stop the task or restart it if the idle state resumes. As an example, these idle options are useful when you know that your task might require many system resources to run. Setting them to run when your PC or device is idle means that you are not going to be bothered by programs working slowly because of this task eating up most of your computer's resources.
Since a task might run for a long time, the Task Scheduler allows you to set conditions for the task so that it starts only when the computer is on AC power, and to stop the task if you switch to battery power. If your computer is in sleep mode and it is the time to run the task, you can set the computer to wake up and run the task.
If you know that you need a specific network connection for running the task, check the box that says "Start only if the following network connection is available" and choose the connection that you are interested in.
How to set the failure behavior of a task
Task Scheduler allows you to make settings which come in handy in special situations such as the failure of the task or when the running task does not end when requested. Go to the Settings tab in the Create Task wizard.
You can make the following settings:
- Allow the task to run on demand. Otherwise, it is only run when both the triggers and conditions are met.
- If the task is based on a schedule which is missed, you can set the task to be run as soon as possible.
- For the cases when the task fails, you can set it to be restarted every 1, 5, 10, 15, 30 minutes, or 1-2 hours. The restart can be attempted for the times that you set.
- If you think that something has gone wrong with your task, and it runs longer than 1, 2, 4, 8, 12 hours, or 1-2 days, you can set it to stop.
- If a task is not scheduled to run again, you can set your computer to automatically delete the task after 30, 90, 180, 365 days or immediately.
- If the task is already running and the time comes for it to run again, you can choose one of the following options: "Do not start a new instance" (the first instance of the task continues to run), "Run a new instance in parallel" (the first task instance continues to run, and the new task instance also starts), "Queue a new instance" (the new tasks instance runs after the first task instance finished), and "Stop the existing instance" (the first task instance is stopped, and the new task instance is started).
When you have set everything as you wanted, press the OK button and the task is instantly created, and you can find it anytime you want in the Task Scheduler Library.
Do you use Task Scheduler to create advanced tasks?
As you can see, the Task Scheduler offers a considerable number of settings which help you create lots of advanced tasks. While not all options seem easy to understand at first, by carefully reading this article and experimenting on your own, you should quickly get the hang of it and gain more control over your computer. If you have any questions about the Task Scheduler, do not hesitate to ask in the comments section below.