Hi all,
I'm reading this post since I'm having "Access is denied" on RegisterTaskDefinition, launching my application from a domain user which belongs to Administrators group on the machine (I'm trying on both Windows 7 and Windows Server 2008 R2).
What is strange is that thientan0206 said that the first operation works fine ("First, I create one task under administrator account like this one: [...] It's good, I can create the task, and let it run"). In my case, this simply operation already causes the "Access is denied" message error.
I tried to copy and paste these lines of code in a sample app:
using (TaskService ts = new TaskService())
{
TaskDefinition td = ts.NewTask();
DailyTrigger dailyTrig = new DailyTrigger();
dailyTrig.StartBoundary = DateTime.Now;
dailyTrig.DaysInterval = 2;
td.Triggers.Add(dailyTrig);
ExecAction ac = new ExecAction("D:\\a.exe");
td.Actions.Add(ac);
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition("TEST", td, TaskCreation.CreateOrUpdate,
"SYSTEM", null, TaskLogonType.ServiceAccount);
}
...launched it and it doesn't work: I'm getting that annoying message.
Of course, if I try adding the same activity using the Task Scheduler snap-in, the activity gets created succesfully...
Why? What I'm doing wrong?