I'm creating a Windows Scheduled Task from a MVC app # by using the c# TaskService namespace.
It normally works fine if the IIS AppPool is set to run as the LocalService user, but every now and then we find a server where it fails to create the Scheduled Task. If we change the AppPool user to a local (admin) user, then it works. But I would prefer to run the AppPool under a system user of some kind.
I don't have any specific error message yet as I can't replicate the error myself.
Are there any rigths/settings/permissions that can cause the LocalService user not to be able to create the Scheduled Tasks?
(PS: LocalSystem and the IIS AppPool users also does not work)
using (TaskService ts = new TaskService())
{
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "My Task";
var trigger = new RegistrationTrigger() { Delay = TimeSpan.FromSeconds(1) };
trigger.Repetition.Interval = new TimeSpan(1, 0, 0));
td.Triggers.Add(trigger);
td.Actions.Add(new ExecAction("C:\Folder\program.exe"));
td.Settings.AllowDemandStart = task.AllowDemandStart;
td.Settings.Hidden = task.Hidden;
ts.RootFolder.RegisterTaskDefinition("My Task", td); //Assumption is that error happens on this line
}