How to list scheduled tasks in C #

Before anyone says this is a duplicate, I already checked here , here , here , here and a few other resources, including the MS Scheduler class documentation .

I wanted to be able to list scheduled tasks on my servers using the C # program that I am developing. Some suggested the schtasks.exe MS program, others a third-party library that seems old and only works with the .NET Framework 2.0 and other MS Task Scheduler Class , which seems to be protected, and I haven't seen any example yet, so I understand how can I use it, while others even suggested reading XML files on each remote computer in the C: \ Windows \ System32 \ Tasks folder.

My question is: are tasks on Windows difficult to work using the built-in VS class? Do I have to jump through hoops to make something (sort of) stupid, how to list the tasks already planned on the machine?

Thank,

EDIT:

I ended up using the Process class and ran the schtasks.exe file for all servers. Not quite what I was looking for, but it works. If someone needs a code, just write me and I will post it here. Thank.

+4
source share
2 answers

Ah, System.Threading.TaskScheduler is intended for planning work units in a process that are not related to scheduled tasks that you can create from administrative tools.

, https://taskscheduler.codeplex.com/ - Googled, , - COM- 2004 , " . , .

. " "

void EnumAllTasks()
{
   using (TaskService ts = new TaskService())
      EnumFolderTasks(ts.RootFolder);
}

void EnumFolderTasks(TaskFolder fld)
{
   foreach (Task task in fld.Tasks)
      ActOnTask(task);
   foreach (TaskFolder sfld in fld.SubFolders)
      EnumFolderTasks(sfld);
}

void ActOnTask(Task t)
{
   // Do something interesting here
}
+2

powershell #? powershell .

/ powershell .

powershell # Voila.

0

Source: https://habr.com/ru/post/1665142/


All Articles