This blog contains experience gained over the years of implementing (and de-implementing) large scale IT applications/software.

Windows Batch File to Install Windows Task

@cls
@rem ######################################################################
@rem # Script:  install_task.bat
@rem # Params:  none.
@rem # Desc:    This script installs the task that will run the
@rem #           start.bat on the required schedule.  WinXP or Win2k3
@rem # Author:  D.Griffiths
@rem # Version: 1.0
@rem # History:
@rem #          09-June-2008 – DMG – Created.
@rem #
@rem ######################################################################

@set TN=My_TaskName
@set DAYS=MON,TUE,WED,THU,FRI,SAT
@set TR=C:start.bat
@set ST=05:50:00

@set /P conf=Press return to install task “%TN%”:

@echo Tasks currently scheduled…
@schtasks /Query /FO TABLE

@echo.
@echo Removing existing task if already present…
@schtasks /Delete /TN %TN% /F

@echo.
@echo Installing new task “%TN%”…
@schtasks /Create /RU SYSTEM /SC WEEKLY /D %DAYS% /TN %TN% /TR %TR% /ST %ST%
@IF ERRORLEVEL 1 goto invalid_task

@echo.
@echo Task “%TN%” now scheduled.
@echo.
@echo Tasks currently scheduled…
@schtasks /Query /FO TABLE
@echo.
@echo.
@set /P conf=Press return to exit.
@exit

:invalid_task
@echo.
@echo.
@echo ERROR: There was a problem installing the task.
@echo ERROR: Please try again or check the command syntax.
@set /P conf=Press return to exit.