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.

  1. Schedule a SyncToy backup job (see "Schedule SyncToy" in the included help file for details)
  2. Throw blat and grep into C:\Windows (or anywhere in your PATH)
  3. 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 admin@example.org -to user@example.org -s "SyncToy task result" -serverSMTP mail.example.org
  4. Schedule email.bat to run daily. You'll start receiving emails that look something like this:
    TaskName:      SyncToy
    Last Run Time: 12:30:00, 4/2/2013
    Last Result:   0
On a related note, the Windows 7 version of schtasks supports the /TN parameter for queries:
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"

Folder: \Microsoft\Windows\SyncToy
HostName:                             computername
TaskName:                             \Microsoft\Windows\SyncToy\synctoy
Next Run Time:                        4/3/2013 10:57:34 PM
Status:                               Ready
Logon Mode:                           Interactive only
Last Run Time:                        4/2/2013 11:01:39 PM
Last Result:                          0
Author:                               computername\user
Task To Run:                          "C:\Program Files\SyncToy 2.1\SyncToyCmd.exe" -R
...

/windows | Apr 02, 2013


Subscribe or visit the archives.