我正在尝试使用Task Scheduler Managed Wrapper创建任务。然而,它失败了。
如果我使用本地用户执行此操作,但没有管理员权限,则会因拒绝访问而失败。相反,如果我尝试使用提升用户运行它,代码就会完成而不会出错,但我无法在任务调度程序中看到该任务。
代码直接取自文档:http://taskscheduler.codeplex.com/documentation
并且是:
using (TaskService ts = new TaskService())
{
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Does something";
// Add a trigger that, starting tomorrow, will fire every other week on Monday
// and Saturday and repeat every 10 minutes for the following 11 hours
WeeklyTrigger wt = new WeeklyTrigger();
wt.StartBoundary = DateTime.Today.AddDays(1);
wt.DaysOfWeek = DaysOfTheWeek.Monday | DaysOfTheWeek.Saturday;
wt.WeeksInterval = 2;
wt.Repetition.Duration = TimeSpan.FromHours(11);
wt.Repetition.Interval = TimeSpan.FromMinutes(10);
td.Triggers.Add(wt);
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction("notepad.exe", "c:\\test.log", null));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition("Test", td);
}
所以我认为这不是代码问题 - 更多与我没有正确使用它有关!
答案 0 :(得分:2)
如果我以管理员身份运行(您必须通过计算机管理执行此操作 - 无法以管理员身份运行任务计划程序),则会显示所有任务。