Taskscheduler类在XP中不起作用 [英] Taskscheduler class not working in XP

查看:99
本文介绍了Taskscheduler类在XP中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个安排任务的程序。虽然这在Windows7机器上运行良好,但它在XP上引发了错误。



这是代码:



Hi I have a program that schedules task. While this runs fine on Windows7 machine, it throws an error on XP.

Here is the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TaskScheduler;

namespace MyTaskScheduler
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string STR_DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                string taskName = "MyTask";
                string taskFolder = "MyTaskFolder";

                Console.WriteLine("Creating task");
                ITaskService taskScheduler = new TaskSchedulerClass();
                taskScheduler.Connect(null, null, null, null);

                ITaskFolder rootFolder = taskScheduler.GetFolder(@"\");
                bool _found = false;
                foreach (ITaskFolder fol in rootFolder.GetFolders(0))
                {
                    if (fol.Name == taskFolder)
                        _found = true;
                }
                if (!_found)
                    rootFolder.CreateFolder(taskFolder, null);
                ITaskFolder folder = rootFolder.GetFolder("\\" + taskFolder);

                _found = false;
                foreach (IRegisteredTask tsk in folder.GetTasks(0))
                {
                    if (tsk.Name == taskName)
                        _found = true;
                }  
                if (_found)
                    folder.DeleteTask(taskName, 0);

                Console.WriteLine("Creating new task");
                ITaskDefinition taskDef = taskScheduler.NewTask(0);
                taskDef.RegistrationInfo.Description = "Opens notepad at the scheduled times";
                taskDef.RegistrationInfo.Author = "Monica";
                taskDef.Settings.Enabled = true;
                taskDef.Settings.Hidden = false;
                taskDef.Settings.DisallowStartIfOnBatteries = false;
                taskDef.Settings.WakeToRun = true;

                IWeeklyTrigger trigger = (IWeeklyTrigger)taskDef.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_WEEKLY);
                //if (intWeekDays != 0)
                trigger.DaysOfWeek = (short)10;
                trigger.Id = "MyTimeSet";
                trigger.StartBoundary = DateTime.Now.Date.AddHours(10).AddMinutes(15).AddSeconds(20).ToString(STR_DateTimeFormat.Replace(" ", "T"));

                IExecAction action = (IExecAction)taskDef.Actions.Create(_TASK_ACTION_TYPE.TASK_ACTION_EXEC);
                action.Id = "MyRun";

                string actionFile = "notepad.exe";

                action.Path = String.Concat("\"", actionFile, "\"");

                action.Arguments = String.Format("argus \"{0}\"", "argument1");

                IRegisteredTask regTask = null;

                regTask = folder.RegisterTaskDefinition(taskName, taskDef, (int)_TASK_CREATION.TASK_CREATE_OR_UPDATE, null, null, _TASK_LOGON_TYPE.TASK_LOGON_NONE, "");

                Console.WriteLine("task created");                
            }
            catch (Exception e1)
            {
                Console.WriteLine(e1.ToString());
            }
        }
    }
}









我在XP机器上运行这个程序时得到的错误是:







The error I get when I run this program on XP machine is:

System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class     factory for component with CLSID {0F87369F-A4E5-4CFC-BD3E-73E6154572DD} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).   at TaskScheduler.Program.Main(String[] args)







有人可以告诉我这里哪里出错。



谢谢,Monica




Can someone advise where am I going wrong here.

Thanks, Monica

推荐答案

Task Scheduler API有两个版本。你的TaskScheduler类显然使用的是2.0版,它在XP上并不存在,仅适用于Vista及以上版本。
There are two versions of the Task Scheduler API. Your TaskScheduler class is apparently using version 2.0, which doesn''t exist on XP, only on Vista and above.


这篇关于Taskscheduler类在XP中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆