Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scheduled Task Error Notification
#1
I have a way for QM to email me things (via blat (blat.net)) so all I need is for QM to grab some info for me.

Is there a way for QM to tell me when a scheduled job fails not on the particuar process side but the schedule itself? For example, I dont need to know when a batch file fails in an ftp process cuz it has the worng ip address in it but i would like to know when a process fails cuz the network is down and cant get to that batch file.

does that make sense?

thanks
#2
Function GetScheduledTaskStatus
Code:
Copy      Help
;/
function# $taskName [DATE&nextRunTime] [DATE&lastRunTime] [str&statusString] [int&lastExitCode] [int&isRunning]

;Gets some information about a scheduled task.
;Returns 1 if successful (although some variables may be emty if fais to retrieve), or 0 if task does not exist or cannot be opened.


;nextRunTime - next run time or 0 if not scheduled.
;lastRunTime - last run time or 0.
;statusString - if the task could not be started, contains error description. If ok, empty.
;lastExitCode - program's exit code or 0.
;isRunning - 1 if the task is curently running, 0 if not.


;Use 0 for arguments you don't need.

;Reference: search for ITask in http://msdn.microsoft.com/library


;def SCHED_S_TASK_READY 0x00041300
def SCHED_S_TASK_RUNNING 0x00041301
;def SCHED_S_TASK_DISABLED 0x00041302
def SCHED_S_TASK_HAS_NOT_RUN 0x00041303
;def SCHED_S_TASK_NO_MORE_RUNS 0x00041304
;def SCHED_S_TASK_NOT_SCHEDULED 0x00041305
;def SCHED_S_TASK_TERMINATED 0x00041306
;def SCHED_S_TASK_NO_VALID_TRIGGERS 0x00041307
;def SCHED_S_EVENT_TRIGGER 0x00041308

interface ITaskScheduler :IUnknown SetTargetComputer GetTargetComputer Enum Activate Delete NewWorkItem AddWorkItem IsOfType {148BD527-A2AB-11CE-B11F-00AA00530503}
interface IScheduledWorkItem :IUnknown CreateTrigger DeleteTrigger GetTriggerCount GetTrigger GetTriggerString GetRunTimes GetNextRunTime SetIdleWait GetIdleWait Run Terminate EditWorkItem GetMostRecentRunTime GetStatus GetExitCode SetComment GetComment SetCreator GetCreator SetWorkItemData GetWorkItemData SetErrorRetryCount GetErrorRetryCount SetErrorRetryInterval GetErrorRetryInterval SetFlags GetFlags SetAccountInformation GetAccountInformation
interface ITask :IScheduledWorkItem SetApplicationName GetApplicationName SetParameters GetParameters SetWorkingDirectory GetWorkingDirectory SetPriority GetPriority SetTaskFlags GetTaskFlags SetMaxRunTime GetMaxRunTime {148BD524-A2AB-11CE-B11F-00AA00530503}
;
ITaskScheduler ts._create("{148BD52A-A2AB-11CE-B11F-00AA00530503}")
ITask task

BSTR bName=taskName
int hr=ts.Activate(bName uuidof(ITask) &task); if(hr) ret

SYSTEMTIME st
if(&lastRunTime)
,hr=task.GetMostRecentRunTime(&st)
,if(hr) lastRunTime=0; else lastRunTime.fromsystemtime(st)

if(&nextRunTime)
,hr=task.GetNextRunTime(&st)
,if(hr) nextRunTime=0; else nextRunTime.fromsystemtime(st)

if(&lastExitCode or &statusString)
,if(!&lastExitCode) &lastExitCode=_i
,lastExitCode=0
,hr=task.GetExitCode(&lastExitCode)
,if(&statusString)
,,sel(hr)
,,,case [0,SCHED_S_TASK_HAS_NOT_RUN] statusString.all
,,,case else statusString.dllerror("" "" hr)

if(&isRunning)
,hr=task.GetStatus(&isRunning)
,isRunning=isRunning=SCHED_S_TASK_RUNNING

ret 1

Examples
Code:
Copy      Help
ClearOutput

str name="notepad"

DATE nextrun lastrun
str statusstr
int exitcode
int isrunning

GetScheduledTaskStatus name nextrun lastrun statusstr exitcode isrunning

out nextrun
out lastrun
out statusstr
out exitcode
out isrunning

Code:
Copy      Help
str s
DATE d
if(!GetScheduledTaskStatus("task name" 0 d s)) end "task does not exist"
if(s.len)
,out "could not start, %s" s
else
,out "successfully started at %s" _s.from(d)
#3
wow...that works great!!!
thanks.

is there a way to get all the names in the st folder to plug into it?
An old blog on QM coding and automation.

The Macro Hook
#4
You can enumerate files in c:\windows\tasks, or use ITaskScheduler.Enum.
#5
HAHAHAHA...i was trying to enumerate "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\::{D6277990-4C6A-11CF-8D87-00AA0060F5BF}"
:lol:
An old blog on QM coding and automation.

The Macro Hook
#6
I think this format can be used only with ShellExecute[Ex] (run uses it).
#7
DANG!!!

i got this thing to send me emails when my server errors out on a task! "and how" do you you ask?....."triggers"!!!


thanks!
An old blog on QM coding and automation.

The Macro Hook


Forum Jump:


Users browsing this thread: 1 Guest(s)