NOTE: The following examples and file paths are from Windows 7. XP paths may be different for some programs as well as for MS Office (Office 2007 is used in the example below) on your Computer.
Also, due to some sites not allowing the use of back slashes, the examples below use forward slash for folder paths. When creating your batch files, use a back slash in the folder path.
- start /d C:/Windows/System32 calc.exe
- start /d "C:/Program Files/Mozilla Firefox" firefox.exe
- https://www.bankofamerica.com start /d C:/finance/spreadsheets budget.xls
Let's quickly review each command listed above. First, the Start command instructs Windows to open a separate window within which the program executes.
Second, the /d is called a Switch and instructs the Windows to read the following information as a file or command path for locating the program. If there are spaces in the path, the complete path will need to be placed in double quotes.
Third, the name of the file to be executed is added, including its extension.
And fourth, if there is a file or URL to be opened, then this is where it is placed. For example, the budget spreadsheet budget.xls.
The above is a simple example. Batch files can handle more complex tasks. Below is an example of a complex batch file...
- @echo off
- color 3
- title Conditional Shutdown
- set /p name=enter a name:
- :start
- cls
- echo Hi, %name%
- echo.
- echo 1.Shutdown
- echo 2.Quit
- set /p choice=enter your choice 1,2:
- if %choice%==1 goto shutdown
- if %choice%==2 exit
- :shutdown
- cls
- set /p sec=enter the number of seconds that you wish the computer to shutdown in:
- set /p msg=enter the shutdown message you wish to display:
- shutdown -s -f -t %sec% -c "%msg%
- echo shutdown initiated at %time%
- set /p cancel=type cancel to stop shutdown
- if %cancel%==cancel shutdown -a
- if %cancel%==cancel goto start