Hi, All
I also have problems with task edition. Shortly:
I also have problems with task edition. Shortly:
- "RegisterChanges" is not needed in case we want only to change "Enabled". Moreover in case it will be called - "Enabled" flag will be returned to previous state. Don't know why this happens.
-
In my case task contains only single action to start exe file. What I want to do is to modify path to exe file. Here it is reworked piece of code:
using (var ts = new TaskService())
{
var alreadyPresentTask = ts.FindTask(settings.TaskSchedulerTaskName);
foreach (var action in alreadyPresentTask.Definition.Actions)
{
if (action is ExecAction)
{
var execAction = action as ExecAction;
if (null != execAction)
{
var root = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var newPath = System.IO.Path.Combine(root, Path.GetFileName(execAction.Path));
string oldPath = execAction.Path;
execAction.Path = newPath;
string oldWorkingDirectory = execAction.WorkingDirectory;
execAction.WorkingDirectory = root;
}
}
}
alreadyPresentTask.RegisterChanges();
alreadyPresentTask.Enabled = true;
}
As You can see "RegisterChanges" here called before modification of Enabled flag, because in opposite case task wouldn't be enabled. But main problem is what this code works in "windows 8" but work partially in "windows xp": Modified only "Enabled" flag properly, but paths remains unchanged. Without any exceptions, errors etc... Simply do nothing. Can someone help me?