Batch (.bat)
A .bat wrapper around any job; uses curl.exe, built into Windows 10 and 11. The job's output goes to a temporary file; on a failure its last 20 lines go with the alert.
The code
This is the code the Code tab generates (with start and errors ticked). In the app it already contains your job's own address.
@echo off
REM Save as C:\jobs\taskbeacon-run.bat
REM Task Scheduler > Action: Start a program
REM Program: C:\jobs\taskbeacon-run.bat
REM Runs your job, then reports success or failure from its exit code.
set "TB=https://taskbeacon.io/ping/your-job-id"
curl.exe -fsS -m 10 "%TB%/start" >nul
REM --- your job here (a program, a script, another .bat with call): replace the path ---
REM its output goes to a temporary file: shown below, and its last 20 lines go with a failure
set "TB_LOG=%TEMP%\taskbeacon-%RANDOM%.log"
call "C:\path\to\your-job.bat" > "%TB_LOG%" 2>&1
set TB_RC=%ERRORLEVEL%
type "%TB_LOG%"
type nul > "%TB_LOG%.tail"
if not "%TB_RC%"=="0" powershell.exe -NoProfile -Command "Get-Content -LiteralPath $env:TB_LOG -Tail 20 | ForEach-Object { if ($_.Length -gt 300) { $_.Substring(0, 300) } else { $_ } }" > "%TB_LOG%.tail" 2>nul
REM the exit code goes at the end of the address: /0 = OK, any other number = failed
curl.exe -fsS -m 10 --data-binary "@%TB_LOG%.tail" -H "Content-Type: text/plain" "%TB%/%TB_RC%" >nul
del "%TB_LOG%" "%TB_LOG%.tail" 2>nul
exit /b %TB_RC%How it works
The .bat pings /start when the job begins and, when it ends, the address with its exit code at the end: /0 is OK, any other number a failure, sent with the last 20 lines of output. It sends no row count.
Untick options on the Code tab to leave parts out; untick Send output lines to send no output, only the error or exit code. See what can be reported.
Run on a schedule
Save the code as C:\jobs\taskbeacon-run.bat, put your job's command where it says your job here, and create a task (one line, in a Command Prompt):
schtasks /Create /TN "Nightly export" /SC DAILY /ST 02:00 /TR "C:\jobs\taskbeacon-run.bat"
In Task Scheduler set Start in to your job's folder if it uses relative paths.
Common problems
- A failed job shows as OK. The wrapper reports the exit code of the command after
call. If that is another .bat, it must end withexit /b 1(or another number) when something went wrong; a .bat ends with the code of its last command. - curl.exe not found. It is built into Windows 10 and 11. On older Windows, give the full path to a
curl.exe. - A % sign disappears. Inside a .bat, a literal
%must be written%%. - Runs by hand, not on schedule. Tick Run whether user is logged on or not, and use UNC paths (
\server\share\…) instead of mapped drive letters.
Use cases: Task Scheduler Last Run Result 0x0, but the script failed. More questions: FAQ.