Batch file to test if scheduled task last result= 0x0

Hi Experts,

Can anyone give me a batch file  if statement to check last result of a scheduled task.

We use a scheduled task batch file that renames and moves backup files but it copies over good backups with bad ones.

I'd like to test if last resullt = 0x0 prior to the copy to ensure I don't loose good backups.

Thanks,

Scott

closehauledAsked:
Who is Participating?
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Sorry for schtask(s).
/query /TN  is only supported starting with Vista - didn't know that. That's making things a bit more complicated. We have to use CSV format. and see for the appropriate column, and filter for the task name.



@echo off
set result=
for /F "delims=, tokens=7" %%R in ('schtasks /query /fo csv /v ^| findstr /L /C:"My Task"') do set result=%%R

Open in new window

0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
You can use

for /F "tokens=2 delims=:" %%R in ('schtask /query /TN "Taskname" /v ^| findstr /i result') do set /A result=%%R

with "Taskname" replaced by the task you want to check.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Correction:
for /F "tokens=2 delims=:" %%R in ('schtask /query /v /FO list /TN "Taskname" /v ^| findstr /i result') do set /A result=%%R

Open in new window

0
 
closehauledAuthor Commented:
Thanks for getting back to me on this.

The /tn "taskname" parameter seems not valid for /query also had to use schtasks.

 
0
 
closehauledAuthor Commented:
Thanks, it works a charm.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.