DOS batch script to check if schtasks are working or not

Can anyone help..

I am writing a DOS batch script which calls a command called schtasks to initiate a dos batch script... however I would like some error checking involved to check the following:-

1. if the schedule task fails to start it errors.  - e.g. task failed to start
2. if the schedule task starts but fails to complete, it errors - e.g. task failed to complete
3. if the schedule task completes - e.g. task completed successfully
rakkadAsked:
Who is Participating?
 
NVITCommented:
Does this help?
schtasks /query /fo LIST /v /tn "Name of task" | find /i "Last Result:"

Open in new window

0
 
NVITCommented:
Or...
for /f "tokens=1,2 delims=:" %%A in ('schtasks /query /v /fo list /tn "Name of task" ^| find /i "last result"') do (call :Next %%B)
goto :eof

:Next
for %%A in (%1) do echo %%A

Open in new window

0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
NewVillageIT, why that complicated? And it is not removing the white space ...
for /f "tokens=3 delims=	: " %%A in ('schtasks /query /v /fo list ^| find /i "last result"') do @echo %%A

Open in new window

However, all suggestions up to now only display the last result error code. And it won't get better, because the only fact you can know is that 0 means "ok". Any other code reflects an issue, but you won't know more as long as you did not test yourself in which case which last result value is shown.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
NVITCommented:
Qlemo... What's a simpler way to get the task result? I'd appreciate your help.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
See my code.%%A contains the raw value we can assign to a var to check for known result codes.
0
 
rakkadAuthor Commented:
This task worked
0
 
NVITCommented:
Rakkad... I glad it worked for you.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Objection. http:#a40456326  shows a better way to get the result code (because you do not get a string containing it, but the code itself). The following comments show that you were interested in that.
And I explained what you can expect at most. So I would have expected at least an equal share of points, if not the majority.
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.