---
title: "CAT in Windows Task Scheduler"
description: "Run a CAT test project on a schedule with Windows Task Scheduler — the task, the account, the key, the variables, where the results go"
url: "https://docs.justcat.it/how-to-guides/pipelines-and-schedulers/cat-in-windows-task-scheduler/"
---
# CAT in Windows Task Scheduler


## Before you start

A scheduled task is automation, and CAT recognizes Windows Task Scheduler: the run needs the **Enterprise plan** and a license key — from CAT 3.0 a task without the key stops before any test runs — see [Integrations](https://docs.justcat.it/reference/integrations/ "Integrations reference"). Decide which Windows account the task runs as — a service account is the usual choice — because three things are stored per user: the license key (`%APPDATA%\CAT\.catconfig`), user-level environment variables, and the PowerShell module when installed with `-Scope CurrentUser`.

## Prepare the account

Sign in as that account once (or run the commands under it with `runas`) and:

1. Install [CAT CLI](https://docs.justcat.it/reference/cat-cli/installation/ "Install CAT CLI") — `winget install DataTools.CATCLI --version 3.0.0` (the version you tested with — pin it), or the installer; it installs per machine. (Or the PowerShell module with `-Scope AllUsers`.)
2. Set the key: `catcli instance --setLicenseKey "<key>"` (or `Set-CatInstance -LicenseKey`).
3. Define the environment variables the project file references — `DWH_CONNECTION_STRING` and friends — at **machine** level (seen by every account, new sessions) or at user level for that account. See [Use environment variables](https://docs.justcat.it/how-to-guides/organize-and-run-tests/use-environment-variables/ "Use environment variables").
4. Run the project by hand from that account once: `catcli run -p "D:\CAT\DWH\DwhTests.cat.yaml"`. If it works here, it works in the task.

## Create the task

*Task Scheduler → Create Task…*:

| Tab | Setting |
|---|---|
| **General** | *When running the task, use the following user account*: the prepared account. **Run whether user is logged on or not.** |
| **Triggers** | the schedule — daily at 06:00, after every load, whatever the tests are for |
| **Actions** | *Start a program* — Program: `catcli` (or its full path, `C:\Program Files\CAT CLI\catcli.exe`); Arguments: `run -p "D:\CAT\DWH\DwhTests.cat.yaml" -l Error`; *Start in*: the project's folder, so relative paths in the project file resolve |
| **Settings** | *Stop the task if it runs longer than …* — a ceiling that suits your run |

With the PowerShell module the action is `pwsh` with arguments `-NoProfile -File "D:\CAT\Run-DwhTests.ps1"` and a script that imports the module and calls `Invoke-CatProject`.

## Results

The task has no screen to read; give the project [outputs](https://docs.justcat.it/reference/outputs/introduction/ "Outputs") — an Excel file with `{timestamp}` in the name for people, a [database table](https://docs.justcat.it/reference/outputs/database-outputs/ "Database outputs") or JSON for a process that reacts. `-l Error` writes the failed tests' details to CAT's log (`Documents\CAT\Logs\` of the task's account). Task Scheduler's *Last Run Result* is CAT's exit code: `0` when the run completed whatever the test results, non-zero when the project could not be opened or the sign-in and plan check refused it — see [Results and exit codes](https://docs.justcat.it/reference/integrations/#results-and-exit-codes "Results and exit codes").

## Related

* [Integrations](https://docs.justcat.it/reference/integrations/ "Integrations reference") — plan, key, tool, secrets, results.
* [CAT in SQL Server Agent](https://docs.justcat.it/how-to-guides/pipelines-and-schedulers/sql-agent-cat-cli/ "CAT in SQL Server Agent") · [CAT in cron](https://docs.justcat.it/how-to-guides/pipelines-and-schedulers/cat-in-cron/ "CAT in cron") — the same on a database server and on Linux.

