Unable to update task (E_ACCESSDENIED)

Jun 21, 2013 at 5:19 PM
I've come across several threads related to this, but all of them state they're able to update until they change users. I can't even do that.

Here is the code below

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Win32.TaskScheduler;

namespace ConsoleApplication1 {
  class Program {
    static void Main(string[] args) {
      var p = new Program();

    void EnumAllTasks() {
      using (TaskService ts = new TaskService())

    void EnumFolderTasks(TaskService ts, TaskFolder fld) {
      var tasks = fld.Tasks.Where(t => t.Name.Equals("test-task", StringComparison.OrdinalIgnoreCase));

      foreach (Task task in tasks)
        ActOnTask(ts, task);

    void ActOnTask(TaskService ts, Task t) {
      var ea = (ExecAction)t.Definition.Actions.First();
      ea.Path = ea.Path + ".coolio/test.exe";
      UpdateFirstAction(ts, t, new ExecAction(ea.Path+".coolio/test.exe",ea.Arguments,ea.WorkingDirectory));
      // Do something interesting here

    void UpdateFirstAction(TaskService ts, Task t, Microsoft.Win32.TaskScheduler.Action action) {
      if (t.TaskService.HighestSupportedVersion >= new Version(1, 2)) {
      ts.RootFolder.RegisterTaskDefinition("test-task", t.Definition);

I've tried running this from VS 2012, and directly from the CLI. I created the task manually from the same account that I'm trying to update it from (never logged out). I checked the t.Definition.Principle.UserID and it matches what's being reported for the 'Author' from the task scheduler snapin itself.

What am I missing?
Jun 21, 2013 at 9:53 PM
You likely need to run the application as Administrator.
Jun 24, 2013 at 7:35 PM
It's really hard for me to believe that 'run as admin' is the correct answer to this issue. I have no doubt it would work, but I also have no doubt there are other less drastic measures that would work also.