I need to pull out of the task scheduler all the files that they run when the system starts, read many methods, but third-party libraries that are not included in the standard studio are used everywhere, I found where the scheduler files themselves are, this is normal xml, but without extension. c: \ Windows \ System32 \ Tasks \ this is for win7, the question is how do I see them programmatically. Here I do the standard. Unfortunately, I could not find another way how to get the systems started at startup from the scheduler.

string path = @"c:\Windows\System32\Tasks\ "; // смотрим есть ли файлы с таким расширением string[] filesname = Directory.GetFiles(path, "*.*"); Console.WriteLine(String.Join(" ",filesname)); 
  • Parsing XML is simple: you can use an inline XDocument , for example. But most likely nobody will tell you anything about the format and meaning of the content, since these files are not intended for processing by external utilities. - VladD
  • @VladD I understand this, only then how can I get to tasks in the scheduler bypassing third-party libraries. WMI doesn't show either - Vladimr Vladimirovoch
  • Well, you can meditate on the format of these files and try to guess what it means in them. With a good deal of probability, there is just a collection of serialized objects. - VladD
  • @VladD duck format is still not, I can not even pick it up than that - Vladimr Vladimirovoch
  • and because of what such hatred to third-party libraries? - Monomax

1 answer 1

Instead of parsing XML, it’s better to use the task scheduler's COM objects library . It should be part of the OS, at least starting with Windows 7.

 //Reference: COM -> Task scheduler 1.1 type library using System; using System.Collections.Generic; using System.ComponentModel; using System.Text; using System.Runtime.InteropServices; using TaskScheduler; ... static void PrintFolder(ITaskFolder folder) //метод для рекурсивного обхода каталогов { IRegisteredTaskCollection coll = null; ITaskDefinition def = null; ITaskFolderCollection folders = null; IExecAction exec = null; try { coll = folder.GetTasks(0); //найдем задачи в каталоге foreach (IRegisteredTask item in coll) { if (def != null) { Marshal.ReleaseComObject(def); def = null; } if (exec != null) { Marshal.ReleaseComObject(exec); exec = null; } def = item.Definition; bool autostart = false; foreach (ITrigger trig in def.Triggers) { //нас интересуют только задачи, запускающиеся при включении или входе пользователя if (trig.Type == _TASK_TRIGGER_TYPE2.TASK_TRIGGER_BOOT || trig.Type == _TASK_TRIGGER_TYPE2.TASK_TRIGGER_LOGON) { autostart = true; break; } } if (autostart) { //выведем информацию о задаче Console.Write( item.Name + " "); foreach (IAction act in def.Actions) { if (act.Type != _TASK_ACTION_TYPE.TASK_ACTION_EXEC) { Console.Write( "(" + act.Type.ToString() + ")"); } else { exec = (IExecAction)act; //выведем командную строку, запускаемую задачей Console.Write( "(" + exec.Path + " " + exec.Arguments + ")"); } } Console.WriteLine(); } } //обходим подкаталоги текущего каталога folders = folder.GetFolders(0); foreach (ITaskFolder item in folders) { PrintFolder(item); } } finally { if (coll != null) Marshal.ReleaseComObject(coll); if (def != null) Marshal.ReleaseComObject(def); if (folders != null) Marshal.ReleaseComObject(folders); if (exec != null) Marshal.ReleaseComObject(exec); } } public static void PrintTasks() { TaskScheduler.TaskScheduler ts = null; ITaskService its = null; ITaskFolder folder = null; try { ts = new TaskScheduler.TaskScheduler(); its = (ITaskService)ts; //подключаемся к локальной машине its.Connect(); //получаем корневой каталог задач folder = its.GetFolder("\\"); //рекурсивно выводим задачи PrintFolder(folder); } finally { if (folder != null) Marshal.ReleaseComObject(folder); if (its != null) Marshal.ReleaseComObject(its); if (ts != null) Marshal.ReleaseComObject(ts); } } 
  • Cool! Thank you. this is what you need - Vladimr Vladimirovoch