Search code examples
vb.netscheduled-taskswindows-task-scheduler

TaskScheduler To Find Tasks on a Server


Researching online I have found classes like TaskScheduler, ServiceController, and Task Scheduler Managed Wrapper. However I have not found good examples of how to use this for what I need.

I have a bunch of servers and in this vb.net program one of my co-workers made I need to add implementation to pick a server from a dropdown list and find all the tasks that that server has running.

What I need to figure out is how to use any of these task scheduler classes to basically input a server name and get a list of the tasks back. Or get an enumerator to go through them and pull information from each task, like enabled/disabled, running or not, etc.


Solution

  • Here's an excellent package for doing just this:

    And a quick sample from the Wiki that'll get you started:

    Private Sub EnumAllTasks()
      EnumFolderTasks(TaskService.Instance.RootFolder)
    End Sub
    
    Private Sub EnumFolderTasks(ByVal fld As TaskFolder)
      For Each task As Task In fld.Tasks
        ActOnTask(task)
      Next
    
      For Each sfld As TaskFolder In fld.SubFolders
        EnumFolderTasks(sfld)
      Next
    End Sub
    
    Private Sub ActOnTask(ByVal t As Task)
      ' Do something interesting here
    End Sub