I have problem with modifying tasks which already exists on machine. I'm trying to do this with generated interop interfaces from C# (Interop.TaskScheduler.dll generated from system32/taskschd.dll).
To start with, I can't use other libraries like http://taskscheduler.codeplex.com/. Already tested and it works with library mentioned before. Now when I try do same with generated interfaces nothing changes. Basically what I'm doing:
string STR_DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
string taskName = "taskName",
user = "user",
pass = "pass";
DateTime nextRun = new DateTime.Now.AddDays(7);
TaskSchedulerClass ts = new TaskSchedulerClass();
ts.Connect(null, null, null, null);
IRegisteredTask task = ts.GetFolder("\\").GetTask(String.Format("\\{0}",taskName));
foreach (ITrigger t in task.Definition.Triggers)
t.StartBoundary = nextRun.ToString(STR_DateTimeFormat.Replace(" ", "T"));
ts.GetFolder("\\").RegisterTaskDefinition(task.Path,
task.Definition,
(int)_TASK_CREATION.TASK_UPDATE,
user,
pass,
_TASK_LOGON_TYPE.TASK_LOGON_PASSWORD,
null);
For first look it should be working, but for some reason when I try to assign new datetime for run in line:
t.StartBoundary = nextRun.ToString(STR_DateTimeFormat.Replace(" ", "T"));
It doesn't work. Actually in that foreach it's changed but when I tried to debug and created another foreach which prints value of StartBoundary it shows old value. Am I doing something incorrect? Is there any chance to get it working? :-) Thank you.