This post explains how to write batch scripts in Microsoft Windows to start and stop a particular program. This can be really handy if you want to schedule a program to start and stop at particular times using the Task Scheduler.
The following batch script will start a program in a given directory in minimised window mode:
@echo off
echo.
echo Starting «ProgramName»
echo.
start /D"C:\Program Files\«ProgramDir»\" /MIN /B «ProgramExec.exe»
- Replace «ProgramName» with a description of the program that you are starting. This is for informational purposes only.
- Replace «ProgramDir» with the directory your program is installed.
- Replace «ProgramExec.exe» with the executable program.
The following batch script will stop a particular program executable by killing the process (this is done forcefully).
@echo off
echo.
echo Stopping «ProgramName»
echo.
taskkill /F /IM «ProgramExec»
- Replace «ProgramName» with a description of the program that you are starting. This is for informational purposes only.
- Replace «ProgramExec» with the executable program that you want to stop.
The key to these two batch scripts is:
- Using the start command to start the program. Type start /? in a command prompt to learn more.
- Using the taskkill command to stop the program. Type taskkill /? in a command prompt to learn more.