Hello,
I need to create scheduled tasks, that runs whenever a user is logged on or not.
I have been struggling with it for a while and I think I need some help.
I have been following the discussion http://taskscheduler.codeplex.com/discussions/396537,
but I get errors in both RegisterTaskDeffinition-calls.
This is my code:
using (TaskService ts = new TaskService()) {var taskDefinition = ts.NewTask(); taskDefinition.RegistrationInfo.Description = "This is a test."; taskDefinition.Triggers.Add(new DailyTrigger { DaysInterval = 2 }); taskDefinition.Actions.Add(new ExecAction("notepad.exe"));//ts.RootFolder.RegisterTaskDefinition(@"Test", taskDefinition, TaskCreation.Create, "lap-laser.local\\holtermann", password, TaskLogonType.Password); ts.RootFolder.RegisterTaskDefinition(@"Test", taskDefinition, TaskCreation.Create, "SYSTEM", null, TaskLogonType.ServiceAccount); }
When using the first RegisterTaskDeffinition I get a COMException. ((41,4):LogonType)
When using the second RegisterTaskDefinition I get an UnauthorizedAccessException.
(HRESULT: 0x80070005 (E_ACCESSDENIED))
I don't know how to solve this problem, for any help I would be very thankfull!
This is the last problem of my project and right now I am not able to solve it.
Thank you very much for any help.
Best regards
riehol