Check Task Scheduler Libray if a certian Task exists with VB.Net

~OSD~ 2,201 Reputation points
2022-09-29T11:14:19.12+00:00

Hi,

Is it possible to check in VB.net if a desired Task exists under Task Scheduler , see below screenshot.

246014-image.png

Developer technologies | VB
Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other
A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 91,511 Reputation points
    2022-09-29T11:49:11.44+00:00

    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  
    

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.