Emailing results from Windows XP Scheduled Tasks #
The Windows 7 Task Scheduler includes a built-in email option, something XP doesn't offer. A simple workaround is to use blat and a batch file. We'll use a SyncToy scheduled task in this example.
On a related note, the Windows 7 version of schtasks supports the /TN parameter for queries:
- Schedule a SyncToy backup job (see "Schedule SyncToy" in the included help file for details)
- Throw blat and grep into C:\Windows (or anywhere in your PATH)
- Create a batch file (e.g., C:\scripts\email.bat) which contains something like this:
schtasks /query /fo list /v | findstr /i "Result: TaskName: Last" | grep SyncToy -A 2 | blat -f firstname.lastname@example.org -to email@example.com -s "SyncToy task result" -serverSMTP mail.example.org
- Schedule email.bat to run daily. You'll start receiving emails that look something like this:
Last Run Time: 12:30:00, 4/2/2013
Last Result: 0
C:\>schtasks /query /?
/TN taskname Specifies the task name for which to
retrieve the information, else all of them.
Sadly, the help text is deceiving; you need to specify the full path, not just the task name (or rather (more accurately), the full path is the task name, though that is not at all clear from the Task Scheduler GUI).
C:\>schtasks /query /v /fo list /tn synctoy
ERROR: The system cannot find the path specified.
C:\>schtasks /query /v /fo list /tn "\Microsoft\Windows\SyncToy\synctoy"
Next Run Time: 4/3/2013 10:57:34 PM
Logon Mode: Interactive only
Last Run Time: 4/2/2013 11:01:39 PM
Last Result: 0
Task To Run: "C:\Program Files\SyncToy 2.1\SyncToyCmd.exe" -R
/windows | Apr 02, 2013
Subscribe or visit the archives