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

~OSD~ 2,126 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

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,606 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,570 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 81,726 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