Automate Program Execution

What Is Windows Task Scheduler?

Task Scheduler is a built-in Windows utility that lets you schedule tasks (like opening apps or running scripts) based on time, system events, or triggers like logon or idle state. It’s incredibly useful for automating repetitive tasks.

Restart an IIS Application Every 5 Minutes

We’ll schedule a task to recycle a specific IIS web application every 5 minutes using a batch file that uses PowerShell or appcmd.

Step 1: Create the Batch Script

We'll use PowerShell inside the batch file to restart the IIS web application.

Let’s assume:

  • Your IIS site is named: MyWebApp

  • IIS is installed and available on your system

#restart_iis_app.bat

@echo off
powershell -Command "Restart-WebAppPool -Name 'MyWebApp'"


# You can also restart the entire IIS site using:

@echo off
powershell -Command "Restart-WebItem 'IIS:\Sites\MyWebApp'"


# Or use appcmd.exe (older systems):

@echo off
%windir%\system32\inetsrv\appcmd stop site /site.name:"MyWebApp"
%windir%\system32\inetsrv\appcmd start site /site.name:"MyWebApp"
  • Save this script as: C:\Scripts\restart_iis_app.bat

Step 2: Create the Task in Task Scheduler

  1. Open Task Scheduler

  2. Click Create Task (not basic)

  3. In General Tab:

    • Name: Restart IIS App Every 5 Minutes

    • Check Run with highest privileges

  4. In Triggers Tab:

    • Click New

    • Begin the task: On a schedule

    • Set to Daily

    • Recur every: 1 day

    • Repeat task every: 5 minutes for a duration of: 1 day

  5. In Actions Tab:

    • Action: Start a program

    • Program/script:

      C:\Scripts\restart_iis_app.bat
  6. In Conditions Tab (optional):

    • Uncheck “Start the task only if the computer is on AC power” if needed.

  7. Click OK


What This Does

Every 5 minutes, the batch script will:

  • Use PowerShell to restart the specific IIS app pool

  • Or restart the site using appcmd

  • Keeps the web app refreshed and stable

Confirm It Works

  • Right-click the task → Run to test it

  • You can also verify in Event Viewer → Windows Logs → System for IIS events

Make Sure:


REFERENCES

Last updated

Was this helpful?