I'm trying to create a task using the Task Scheduler Managed Wrapper. However, it is failing.
If I do it using a local user, without admin privileges, it fails with access denied. Conversely, if I try and run it with an elevated user, the code completes without error, but I then can't see the task in the task scheduler.
Code is just lifted directly from the documentation: http://taskscheduler.codeplex.com/documentation
and is:
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);
}
So I don't think it's a code issue - more to do with me not using it right!
@rene pointed me in the right direction. Hadn't realised you can't see all users' tasks in scheduled tasks in Windows 8.
If I run as admin (you have to do this through Computer Management - can't run Task Scheduler as admin direct) all the tasks show up.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.