Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DOS batch script to check if schtasks are working or not

Posted on 2014-11-20
8
Medium Priority
?
419 Views
Last Modified: 2014-12-06
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
0
Comment
Question by:rakkad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 25

Accepted Solution

by:
NVIT earned 1500 total points
ID: 40455688
Does this help?
schtasks /query /fo LIST /v /tn "Name of task" | find /i "Last Result:"

Open in new window

0
 
LVL 25

Expert Comment

by:NVIT
ID: 40455738
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
 
LVL 71

Expert Comment

by:Qlemo
ID: 40456326
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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 25

Expert Comment

by:NVIT
ID: 40456536
Qlemo... What's a simpler way to get the task result? I'd appreciate your help.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40456992
See my code.%%A contains the raw value we can assign to a var to check for known result codes.
0
 

Author Closing Comment

by:rakkad
ID: 40483243
This task worked
0
 
LVL 25

Expert Comment

by:NVIT
ID: 40483409
Rakkad... I glad it worked for you.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40484606
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question