I have attempted the code below,
using (TaskService ts = new TaskService())
{
Task t = ts.GetTask(taskName);
if (t != null)
{
if (!t.Enabled)
{
t.Enabled = true;
t.RegisterChanges();
}
}
}
Unfortunately the code throws an exception and says I need to use the taskfolder.registerTaskDefinition method. We use a specific account for our tasks.
I have this method that appears to work, but it does not actually set the task to disabled.
I am missing something. No errors, and the task interface says the task was set to disabled in the history, but the task is never actually set to disabled, and continues to run.
static void enabledisableTasks(bool value) {
using (TaskService TS = new TaskService(td.servername))
{
foreach (TasksModified t in listTm)
{
try
{
Task task = TS.GetTask(t.path);
TaskFolder tf = TS.RootFolder;
task.Enabled = value;
tf.RegisterTaskDefinition(task.Path, task.Definition, TaskCreation.CreateOrUpdate, userid, td.password, TaskLogonType.Password,null);
}
catch (System.Security.SecurityException e)
{
Console.WriteLine(string.Format("Error with accessing {0} do to error {1}", t.tname, e.Message.ToString()));
}
}
}
}
```