Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,606 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
Is it possible to check in VB.net if a desired Task exists under Task Scheduler , see below screenshot.
You can enumerate tasks from the Root folder.
A test =>
' Add reference to : TaskScheduler 1.1 Type Library
' Add : Imports TaskScheduler
(Manifest with requireAdministrator to get all tasks)
Dim ts As ITaskService = New TaskScheduler.TaskScheduler()
Try
ts.Connect(Nothing, Nothing, Nothing, Nothing)
Catch ex As Exception
System.Windows.Forms.MessageBox.Show("Error : " & ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
Return
End Try
Dim tf As ITaskFolder = ts.GetFolder("")
If (tf IsNot Nothing) Then
Dim tc As IRegisteredTaskCollection = tf.GetTasks(TaskScheduler._TASK_ENUM_FLAGS.TASK_ENUM_HIDDEN)
If (tc IsNot Nothing) Then
Dim nCount = tc.Count
For n = 1 To nCount
Dim task As IRegisteredTask = tc.Item(n)
Console.WriteLine("Task n°{0} = {1}", n, task.Name)
Next
End If
End If