This project has moved and is read-only. For the latest updates, please go here.

COMException in RegisterTaskDefinition

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


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,

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.



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


Jan 22, 2013 at 3:28 PM

Try reading post and see if that helps. My guess is that you have a permissions problem with the holtermann account.

Jan 23, 2013 at 10: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