1

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
}
4

1 回答 1

0

我不能将其关闭为重复项,因为它有赏金;但作为参考,这里已经回答了

在 Windows 任务计划程序中创建/修改任务所需的权限

“该帐户需要对“任务”目录具有读/写权限。路径如下:%SystemRoot%\system32\Tasks\

但是,还有一个问题是 Windows Server 2003 不喜欢我将本地系统指定为任务将在其下运行的帐户。它似乎不喜欢我传入一个空密码,这是您指定本地系统的方式。我通过在服务器上创建一个本地帐户来运行任务并指定这个新帐户来解决这个问题。”

于 2018-02-02T14:18:08.763 回答