List Scheduler Tasks

by ssi 17. December 2015 12:44
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32.TaskScheduler;
using System.Diagnostics.Eventing.Reader;
 
namespace ListSchedulerTasks
{
    class Program
    {
        static string sFolder = "<MS scheduler folder>";
        static List<SchedulerTasks> SCHEDTASK = new List<SchedulerTasks>();
        static void Main(string[] args)
        {
            string sVer = "15.12.15.a";
            Console.WriteLine("{0}", sVer);
            EnumAllTasks();
            Console.WriteLine("{0}""Its over");
 
            foreach (var ts in SCHEDTASK)
                Console.WriteLine("Name: {0} => next{1} en{2} lst{3} res:{4}", ts.Name, ts.NextRunTime, ts.Enabled, ts.LastRunTime, ts.LastTaskResult);
 
            Console.ReadLine();
        }
 
 
        static void EnumAllTasks()
        {
            using (TaskService ts = new TaskService())
                EnumFolderTasks(ts.RootFolder);
        }
 
        static void EnumFolderTasks(TaskFolder fld)
        {
          
            foreach (Task task in fld.Tasks)
                ActOnTask(task);
            foreach (TaskFolder sfld in fld.SubFolders)
                EnumFolderTasks(sfld);
        }
        static void ActOnTask(Task t)
        {
            if (t.Folder.ToString().Contains(sFolder))
            {
 
              //  Console.WriteLine("Name: {0} => next{1} en{2} lst{3} res:{4}", t.Name, t.NextRunTime, t.Enabled, t.LastRunTime, t.LastTaskResult);
 
                SchedulerTasks rcd = new SchedulerTasks();
                rcd.Name = t.Name;
                rcd.NextRunTime = t.NextRunTime;
                rcd.Enabled = t.Enabled;
                rcd.LastRunTime = t.LastRunTime;
                rcd.LastTaskResult = t.LastTaskResult;
                SCHEDTASK.Add(rcd);
 
 
 
            }
 
 
        }
 
 
    }
}
 
 using System;
 
namespace ListSchedulerTasks
{
    internal class SchedulerTasks
    {
        public bool Enabled { getinternal set; }
        public DateTime LastRunTime { getinternal set; }
        public object LastTaskResult { getinternal set; }
        public string Name { getinternal set; }
        public DateTime NextRunTime { getinternal set; }
    }
}

Tags: , ,

CSharp

Calendar

<<  July 2025  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

RecentComments

None

Development Team @ Shelbysys

We develop custom database applications for our clients. Our development tool of choice is MS Visual Studio. 

Quotations

"The distance between insanity and genius is measured only by success."
Bruce Feirstein