Automatically run a program or launch / open a file in Windows 7
As we learned in the previous tutorial, Windows 7 allows you to create scheduled tasks with the Task Scheduler, to automatically perform a certain action on your computer; that tutorial gave you just enough to get started, and this tutorial will explain in detail how to open a certain file, open a web page in a specific web browser, and how to run a program or application and "pass arguments" to it.
Automatically open a program in Windows 7, and optionally pass arguments
Follow these steps to automatically run a program (with or without arguments), after you have started creating a scheduled task (see link above).
- We assume that you have already gone to Action > Create Basic Task, and that you have already define a trigger (a date / time setting, or an event).
- The next step is to select an Action: choose "Start a program", and click Next.
- Windows 7 will now show you the parameters you can pass to the program, from which start path to run the application, etc. - and you are presented with three fields:
- In the "Program/script Field", you need to supply a valid path to some kind of executable file: either a full-fledged application, a utility program, a batch file, or an executable Windows script.
Tech Tip: if you are using a custom script (a WSH
, JS
, or VBS
file, for example), you may need to pass the script file's path as argument, and use cscript.exe
or wscript.exe
instead under Program/script. If you have this level of experience with Windows scripting, you will know.
Pass a file as argument to your scheduled task
The previous tutorial focused on the quickest and easiest way to create a scheduled task in Windows 7, and so we simply passed a file name in "Program/script", to skip a step and let Windows define on its own the even handler (your default browser for a URL, your default mail handler for an email, etc.) But using both fields allow you to force Windows 7 to open a certain file type or protocol with an application of your own choosing. Example: if your default browser is Internet Explorer, and you want to automatically open a page in Firefox, just used Firefox as Program, and the URL as argument!
- After you have chosen your value for program, you need to enter some arguments that the selected application will execute; these arguments could be...
- ...As simple as a switch (like "
/safe
" to start Outlook 2007 in safe mode with all add-ins disabled) - ...As simple as a path to a local or network file, or remote URL
- ...Or a complex mix of arguments including paths, switches, custom variables, etc. In other words, the more you delve into automated Windows management, the more creative solutions you will find to efficiently manage your own computer, or PC's on a network under your supervision.
- Finally, Windows 7 collects another optional text field under "Start in" - this is exactly the same setting you can customize for regular shortcuts, which forces the application in question to explicitly run in a particular path (necessary option if the program is internally referencing relative paths.
- Once you have finished, click on the Next button, and then on Finish to finalize the creation of the scheduled task. The task will automatically run the program or open the file at the trigger date, time, or event you have specified in the parameters.
Caveat: don't forget to surround any path under "Program/script" with double-quotes if it contains spaces, otherwise Windows 7 will consider the word(s) following the first space as being arguments onto themselves. (You will get a notice from Task Scheduler if this is the case.)
up ↑