Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
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)
                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)

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)

Can someone advise where am I going wrong here.
Thanks, Monica
Posted 27-Mar-13 14:03pm
Edited 27-Mar-13 14:05pm
ThePhantomUpvoter at 27-Mar-13 20:27pm
What version of .NET is installed on the XP machine?
Prasad Khandekar at 27-Mar-13 21:05pm
Hello Monica,
I think you are trying to use COM wrapper for The task scheduler. It's available on Windows Vista & Above. See this KB (

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 495
1 Sergey Alexandrovich Kryukov 429
2 OriginalGriff 360
3 CHill60 280
4 Sascha Lefévre 269
0 Sergey Alexandrovich Kryukov 10,017
1 OriginalGriff 9,495
2 Peter Leow 5,241
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 3,076

Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100