Hi, I create a task using the following code...
Try
What am I missing?
PS - the code to define the triggers looks a bit messy as I'm still getting my head around this - sorry.
Try
Dim ts As New TaskService()
' Create a new task definition and assign properties
Dim td As TaskDefinition = ts.NewTask()
td.RegistrationInfo.Description = "Does something"
td.Principal.RunLevel = TaskRunLevel.Highest
td.Principal.LogonType = TaskLogonType.InteractiveToken
' Create a trigger that will fire the task at 06:00 every day.
Dim dt As New DailyTrigger(1)
dt.StartBoundary = CDate(DateAdd(DateInterval.Day, 1, Now()).ToString("dd/MM/yyyy 06:00:00"))
td.Triggers.Add(dt)
'create a trigger that will fire the task every thursday at 04:00.
Dim wt As WeeklyTrigger = DirectCast(td.Triggers.Add(New WeeklyTrigger()), WeeklyTrigger)
wt.StartBoundary = CDate(DateAdd(DateInterval.Day, 1, Now()).ToString("dd/MM/yyyy 04:00:00"))
wt.DaysOfWeek = DaysOfTheWeek.Thursday
' Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(New ExecAction("notepad.exe", "c:\test.txt", Nothing))
' Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition("TestTask", td)
Catch ex As Exception
MsgBox("error - " & ex.Message)
End Try
...and I'm trying to disable it using the following Try
Dim ts As New TaskService
Dim t As Task = ts.GetTask("TestTask")
t.Enabled = False
t.RegisterChanges()
Catch ex As Exception
MsgBox("error - " & ex.Message)
End Try
...but when I use the code to disable it, the code runs OK, but the task isn't disabled.What am I missing?
PS - the code to define the triggers looks a bit messy as I'm still getting my head around this - sorry.