Click here to Skip to main content
Rate this: bad
good
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)
        {
            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());
            }
        }
    }
}
 

 
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
v2
Comments
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 (http://technet.microsoft.com/en-us/subscriptions/aa381833(v=vs.85).aspx)

1 solution

Rate this: bad
good
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.
  Permalink  
v2

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 310
1 OriginalGriff 295
2 Afzaal Ahmad Zeeshan 224
3 Sergey Alexandrovich Kryukov 195
4 BillWoodruff 160
0 OriginalGriff 6,499
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,193
3 Manas Bhardwaj 4,657
4 Maciej Los 4,120


Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2014
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