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
Save this script as:
C:\Scripts\restart_iis_app.bat
Step 2: Create the Task in Task Scheduler
Open Task Scheduler
Click Create Task (not basic)
In General Tab:
Name:
Restart IIS App Every 5 Minutes
Check Run with highest privileges
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
In Actions Tab:
Action: Start a program
Program/script:
In Conditions Tab (optional):
Uncheck “Start the task only if the computer is on AC power” if needed.
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:
You’re running Task Scheduler with an account that has IIS Admin rights
PowerShell execution policy allows the script to run (
Set-ExecutionPolicy RemoteSigned
)
REFERENCES
Last updated
Was this helpful?