Link to home
Start Free TrialLog in
Avatar of closehauled
closehauled

asked on

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

Avatar of Qlemo
Qlemo
Flag of Germany image

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.
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

Avatar of closehauled
closehauled

ASKER

Thanks for getting back to me on this.

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

 
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, it works a charm.