Creating a Task with the Details View
Once you already know what you are doing, there’s no reason to go through a wizard to create a new task (unless you really like them). Instead, you can just create a new task and fill out the sections with the settings that you want – and naturally, there are more settings available this way.
Note: Everything we’re going to mention here also applies to editing existing tasks, so it’s well worth paying attention.
The first and most obvious fields are the Name, Location, Author, and Description, which are informational and self-explanatory. The Name field should be something short but descriptive, and you should really add a description so you don’t forget why you added this task when you are looking at it a year from now.
The rest of the options are better explained with a bulleted list, so we’ll use one of those now.
- User account allows you to specify which user this task is going to run as. If you want the task to interact with the desktop, you’re going to probably want to use your own user account, which is the default. If you specify the SYSTEM account, you won’t want to save a password.
- Run only when user is logged on – this option is the default, and it will automatically run using your user credentials in and in the current session. If you haven’t logged on, the task won’t run.
- Run whether user is logged on or not – this option is the alternative to the last one, and it will run the task as your user account even if you are not logged in. This is useful for maintenance tasks that need to run even on a shared computer while somebody else is logged on, or if you regularly log out of your PC. You will be prompted to enter your password to create the task, and Windows will use those credentials to automatically log you in for the task.
- Do not store password – If you don’t want your password stored, you can select this option – although it only works in a domain environment and requires the account be given the Logon as batch job permission. This is something you would use in a server environment where you didn’t want to save the passwords, so you use a service account. There are also restrictions on using Windows networking and encryption when using this option. (Summary: for the home user, don’t use this one).
- Run with highest privileges – this option essentially gives the task administrator privileges the same way the User Account Control (UAC) prompt would do it. If you plan to use this for administrative purposes, you will probably want to enable this option.
- Hidden – if you want the tasks to hide from the list by default, you can select this, although displaying of hidden tasks is enabled by default in the view options for Task Scheduler, so it seems fairly silly.
- Configure For – this option should be set to whatever the latest operating system you are running is. Basically, you can create tasks that are meant to be exported and then run on older computers where Task Scheduler has less features. If you set the drop-down to XP, for instance, many of the options on the Triggers page would be missing, as well as in Conditions and Settings.
The Triggers page gives you a whole bunch of options to choose from, and even more advanced settings once you select one of them.
These options are fairly straightforward – when you choose an option from the list, the other settings on the page will adjust to give you more controls. These are the ones on the list:
- On a schedule – this trigger uses a time and date setting to start the task. There are a ton of options in here, and you can also make a task recurring, which is probably the default usage.
- At log on – only triggers when you first login. This could be useful to run a task when you login that requires administrator privileges – if you were to stick that into your Startup folder, it wouldn’t work the way you might expect. You can also use this to only trigger when a specific user logs in, rather than when every user logs in.
- At startup – this triggers when the computer starts up, rather than after you login. If you wanted something to run on boot but before you login, this would be the way to go (although there isn’t a guarantee that it would run before you login, just that it would trigger earlier).
- On Idle – this very useful trigger will only start when your computer is idle and you haven’t been in front of it for a while.
- On an event – you can trigger a scheduled task whenever a particular event happens in the Event Viewer logs. So, for instance, every time that event 5133 shows up in the log, run a task that emails somebody.
- At task creation/modification – essentially you are creating a task that runs automatically once the task is created. It’s a way for Windows to create a task on the fly to run something only under certain conditions, and then you can even use the option to delete the task automatically once it is complete. You probably won’t use this one much.
- On connection / disconnect from user session – you can create tasks that only trigger when you logon or off via Remote Desktop, or when you switch between users on a local PC using fast user switching. This can be useful for running certain tools automatically when you connect to a server, for instance.
- On workstation lock / unlock – this trigger starts a task whenever you lock the screen using WIN + L or unlock it with your password.
It’s worth noting that you can have multiple triggers defined for a single task.
Selecting the “On a schedule” option will give you more things to choose from, like which days of the week you’d like to run the task, and what time. You can choose to make it always happen in universal time instead of a time zone if you have servers that span the globe.
But selecting the “On an event” option, for instance, will give you more selectors to choose the log, source, and Event ID that you are filtering for. It’s all relative to what you choose.
The Advanced settings for Triggers give you a bunch of other options to choose from.
- Delay task for up to (random delay) – this will add in a random delay so the task doesn’t always happen at the exact same time of the day.
- Repeat task every – this will let you repeat the task more often than daily or weekly – if you wanted to have a task that ran every hour, you can use this option to make that happen.
- Stop task if it runs longer than – this option is useful if your task has the potential to run away and never quit. Windows will automatically stop the process after the time specified.
- Activate – this setting (not shown in the screenshot below) will set a time and date at which this trigger will be active. This is useful if you wanted to run something on idle, but not until after a particular date.
- Expire – this allows you to set a task that only works for a month, or two, or whatever time you want to set it to. After the time period specified, the trigger would stop working (if you had multiple triggers, the task would continue to be active).
- Enabled – You can use this to enable or disable a task.
The Actions page is much more self-explanatory… the only option is to create a new action that starts a program. You can technically still create an action that sends an email, but they are removing that ability, so if you need to send an email you’ll be better off with a script instead.
The Program/script box allows you to select the application you want to run, the Add arguments box allows you to pass an argument to that application, and the Start in option allows you to set the working directory.
For instance, if you were to use the Browse button and pick your web browser’s .exe file, you could then put http://www.howtogeek.com into the Add arguments box, and this scheduled task would automatically launch How-To Geek in your default browser when run. You could even set it up to run every morning to automatically open your browser when you login. (Not that we are specifically recommending this, but we’re just saying).
The Conditions tab has more options that work alongside the Trigger to decide whether or not the task will actually run. For instance, you could set a trigger to run every day at 1PM, but if you choose to “start the task only if the computer is on AC power”, it will only run if your laptop is plugged into the wall.
The options are pretty simple:
- Start the task only if the computer is idle for – This will only start the task if the computer is idle for the number of minutes specified in the dropdown. Keep in mind these conditions are in addition to the trigger – so if you set a trigger for 1PM it won’t actually start until after 1PM and after the computer has been idle for x minutes.
- Wait for idle for – this continues to wait for you to take a break and get off the computer for a set amount of time. This should be ideally set to less than what the trigger is set for, so it isn’t continuing to wait from the last time.
- Stop if the computer ceases to be idle – There’s nothing more annoying than coming back to your PC just to find out that it is grinding its gears. This option will make the task stop itself when you come back to the PC.
- Restart if the idle state resumes – This option will let the task start again if you walk away, assuming it didn’t finish the first time.
- Start the task only if the computer is on AC power – you wouldn’t want to run a large backup task when you are running on batteries, and this option allows you to make sure that you are plugged in.
- Stop if the computer switches to battery power – if you had a backup task running and then you unplugged the PC, you probably wouldn’t want that backup task continuing to be running and wasting your battery. This option lets you choose that option.
- Wake the computer to run this task – most computers go into sleep mode these days, and this option allows the computer to automatically wake up and run the maintenance tasks. Very useful for backups at 2AM.
- Start only if the following network connection is available – you can specify that a task runs only when connected to a particular network. For instance, you could specify that whenever you come home and plug into the wired network, a backup would automatically happen. Useful!
The last tab to understand is the Settings tab, which has a lot more options to choose from. The most interesting one is to allow the task to run on demand, which will let you trigger it any time you want.
The options include:
- Allow task to be run on demand – Say you have a backup task set to run once a week, but you decide you want to run a backup right now. By having this option checked, you can run it whenever you want.
- Run task as soon as possible after a scheduled start is missed – If the computer was turned off, it is possible that a triggered time event might not happen. This setting will allow Task Scheduler to go back and see that it was supposed to run, and then trigger it to run right away.
- If the task fails, restart every – You probably won’t use this much, but if you want the task to restart itself automatically, you can use this option, as well as the Attempt to restart option to make sure it doesn’t go crazy and restart itself forever.
- Stop the task if it runs longer than – If you have a task that goes out of control sometimes, you can use this to make sure it doesn’t run forever.
- If the running task does not end when requested, force it to stop – this is useful if the tasks tend to completely hang, because it will force quit them.
- If the task is not scheduled to run again, delete it after – this option will automatically delete the task after the last scheduled time. For instance, you could create a task that does something 5 times, and then self-destructs.
- If the task is already running, then the following rule applies – one of the worst things with scheduled tasks is having the same task running 100 times because the previous instance didn’t close itself properly. This option allows you to make sure that that doesn’t happen by either not starting, running in parallel, queueing, or stopping the old one first.
Hopefully you’ve got a better understanding of how all these options work at this point. There are definitely a lot of options, and a lot of power at your fingertips. You just need to consider how to use it to your advantage.
Running a Scheduled Task on Demand via a Shortcut
We mentioned before that you can run a task on demand, and that is done using the command-line tool schtasks.exe and passing arguments over to specify which task you are trying to run.
You can also use the schtasks utility to create, delete, query, change, end, or display more information about a scheduled task. In fact, if you just type schtasks at the prompt, you’ll see a giant list of every scheduled task. If you use the /? argument instead, you’ll see the syntax.
The full syntax for using the /run argument, which is probably the most useful one, is this:
schtasks /run /TN “taskname”
You can then create a shortcut to run the scheduled task by pointing at the schtasks launcher utility.
What’s the point? Remember when we mentioned how you can use the “Run with highest privileges” option? You can actually create a scheduled task that runs as if the UAC prompt was already selected, and make a shortcut to run an administrator tool without requiring a UAC prompt.