COMException in RegisterTaskDefinition

Topics: Errors
Jan 22, 2013 at 9:19 AM

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

Coordinator
Jan 22, 2013 at 2:28 PM

Try reading post http://taskscheduler.codeplex.com/discussions/277730 and see if that helps. My guess is that you have a permissions problem with the holtermann account.

Jan 23, 2013 at 9:38 AM

Thank you dahall, I will try your proposed post. I hope I can do it today.

The holtermann account is my own account. I use the account every day, and the password is correct too.

With this account / password I can log on and I am admin at my workstation.

It is a domain-account of our company, could this be the reason?

 

Best regards