Exemplo n.º 1
0
        public List <string> GetTaskNameList()
        {
            List <string> result = new List <string>();

            try
            {
                if (!string.IsNullOrEmpty(MachineName))
                {
                    TaskScheduler.TaskScheduler ts = new TaskScheduler.TaskScheduler();
                    if (!string.IsNullOrEmpty(UserName))
                    {
                        ts.Connect(MachineName, UserName, "", Password);
                    }
                    else
                    {
                        ts.Connect(MachineName);
                    }
                    TaskScheduler.ITaskFolder taskFolder = ts.GetFolder("");
                    TaskScheduler.IRegisteredTaskCollection collection = taskFolder.GetTasks(1);
                    foreach (TaskScheduler.IRegisteredTask rt in collection)
                    {
                        result.Add(rt.Name);
                    }
                }
            }
            catch
            {
                result.Clear();
            }
            return(result);
        }
Exemplo n.º 2
0
 protected override void OnDoWork(object sender, DoWorkEventArgs e)
 {
     if (!task.AutoUpdate)
     {
         return;
     }
     try
     {
         TaskScheduler.TaskScheduler ts = new TaskScheduler.TaskScheduler();
         if (!string.IsNullOrEmpty(UserName))
         {
             ts.Connect(MachineName, UserName, "", Password);
         }
         else
         {
             ts.Connect(MachineName);
         }
         TaskScheduler.ITaskFolder taskFolder = ts.GetFolder("");
         TaskScheduler.IRegisteredTaskCollection collection = taskFolder.GetTasks(1);
         foreach (TaskScheduler.IRegisteredTask rt in collection)
         {
             if (rt.Name == TaskName)
             {
                 LastRan    = rt.LastRunTime.ToString();
                 NextRun    = rt.NextRunTime.ToString();
                 TaskStatus = (rt.State == TaskScheduler._TASK_STATE.TASK_STATE_DISABLED) ? "Disabled" : "Enabled";
             }
         }
     }
     catch (Exception ex)
     {
         LastRan = ex.Message;
     }
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            TaskScheduler.TaskScheduler ts;
            ts = new TaskScheduler.TaskScheduler();
            ts.Connect();
            if (ts.Connected)
            {
                var ans  = ts.GetFolder(@"\");
                var anss = ans.GetFolders(0);
                int c    = anss.Count;

                System.Diagnostics.Debugger.Launch();
            }
        }