• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1568
  • Last Modified:

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

0
closehauled
Asked:
closehauled
  • 3
  • 2
1 Solution
 
QlemoC++ DeveloperCommented:
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
 
QlemoC++ DeveloperCommented:
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
 
QlemoC++ DeveloperCommented:
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
 
closehauledAuthor Commented:
Thanks, it works a charm.
0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now