WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Task Scheduler

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Create a Daily Scheduled Task

 Keywords: Create Make Scheduled Task Schedule.Service Daily Trigger

VISTA OR NEWER REQUIRED

Reference: http://msdn.microsoft.com/en-us/library/aa383614(VS.85).aspx

;------------------------------------------------------------------
; This sample schedules a task to start on a daily basis.
;------------------------------------------------------------------

; A constant that specifies a daily trigger.
TriggerTypeDaily = 2
; A constant that specifies an executable action.
ActionTypeExec = 0

;********************************************************
; Create the TaskService object.
service = ObjectCreate("Schedule.Service")
service.Connect()

;********************************************************
; Get a folder to create a task definition in.
rootFolder = service.GetFolder("\")

; The taskDefinition variable is the TaskDefinition object.
; The flags parameter is 0 because it is not supported.
taskDefinition = service.NewTask(0)

;********************************************************
; Define information about the task.

; Set the registration info for the task by
; creating the RegistrationInfo object.
regInfo = taskDefinition.RegistrationInfo
regInfo.Description = "Start notepad at 8:00AM daily"
regInfo.Author = "Administrator"

; Set the task setting info for the Task Scheduler by
; creating a TaskSettings object.
settings = taskDefinition.Settings
settings.Enabled = @TRUE
settings.StartWhenAvailable = @TRUE
settings.Hidden = @FALSE

;********************************************************
; Create a daily trigger. Note that the start boundary
; specifies the time of day that the task starts and the
; interval specifies what days the task is run.
triggers = taskDefinition.Triggers

Trigger = triggers.Create(TriggerTypeDaily)

; Trigger variables that define when the trigger is active
; and the time of day that the task is run. The format of
; this time is YYYY-MM-DDTHH:MM:SS
startTime = "2006-05-02T08:00:00"  ;Task runs at 8:00 AM
endTime = "2015-05-02T08:00:00"

trigger.StartBoundary = startTime
trigger.EndBoundary = endTime
trigger.DaysInterval = 1    ;Task runs every day.
trigger.Id = "DailyTriggerId"
trigger.Enabled = @TRUE

; Set the task repetition pattern for the task.
; This will repeat the task 5 times.
repetitionPattern = trigger.Repetition
repetitionPattern.Duration = "PT4M"
repetitionPattern.Interval = "PT1M"

;***********************************************************
; Create the action for the task to execute.

; Add an action to the task to run notepad.exe.

Action = taskDefinition.Actions.Create( ActionTypeExec )
Action.Path = "C:\Windows\System32\notepad.exe"


;***********************************************************
; Register (create) the task.

rootFolder.RegisterTaskDefinition( "Test Daily Trigger", taskDefinition, 6, , , 3)

Pause("", "Task submitted.")

Article ID:   W18199
Filename:   Create a Daily Scheduled Task.txt
File Created: 2014:05:02:09:38:58
Last Updated: 2014:05:02:09:38:58