-1

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.

TylerH
  • 20,799
  • 66
  • 75
  • 101

1 Answers1

3

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
InteXX
  • 6,135
  • 6
  • 43
  • 80
  • thank you so much for the response. I saw this while looking around and it does look like the nicest and easiet way to go through tasks. But would you know how to get the tasks from a server from the servername? Would that be in the EnumFolderTasks(TaskService.Instance.RootFolder) line? If you could please explain I would greatly appreciate it. – FeenyFan123 Jan 16 '20 at 20:53
  • @FeenyFan123 ~ You can use the `TaskService` constructor overload that accepts a remote machine name. [This example](https://github.com/dahall/TaskScheduler/blob/master/VBTestTaskService/Module1.vb) doesn't do exactly that, but you can adapt it for your own needs. – InteXX Jan 16 '20 at 21:24