且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Windows 任务计划程序中更改已计划任务的运行时间

更新时间:2023-02-17 21:30:13

如果您尝试像这样使用 Task Scheduler C# API 更新任务,则需要声明一个新的 ITaskDefinition.如果您尝试更改现有定义然后重新注册,则不起作用.

If you are attempting to update a task using the Task Scheduler C# API like this, you need to declare a new ITaskDefinition. If you attempt to change the existing definition and then re-Register, it does not work.

IRegisteredTask oldTask = ...
ITaskDefinition task = oldTask.Definition;

//modifications to oldTask.Definition / task

//does **not** work
folder.RegisterTaskDefinition(oldTask.Name, oldTask.Definition, ...
//does work
folder.RegisterTaskDefinition(oldTask.Name, task, ...

答案归于原始海报,请参阅问题评论.我写了这个答案来澄清这个问题,并提请注意这个问题已经得到回答,因为类似的问题困扰了我几天.

Answer credit goes to original poster, see comment on question. I wrote up this answer to clarify the issue, and draw attention to the fact that the question had been answered, as a similar issue troubled me for a few days.