Error 0x80041318 indicates that something in the definition violates either the permissions of what can be registered using the current credentials or violates something that can be registered under the target computer's version of the Task Scheduler. Please post the following to help me better troubleshoot your specific problem:
1) Just before calling RegisterTaskDefintion, have your program output the value of the Xml property for the TaskDefinition and post that here.
2) Tell me what user is being used to create the TaskService instance and what their permissions are on the target computer.
3) Tell me what user and TaskLogonType you are using when calling RegisterTaskDefinition and what their permissions are on the target computer.
1) Just before calling RegisterTaskDefintion, have your program output the value of the Xml property for the TaskDefinition and post that here.
2) Tell me what user is being used to create the TaskService instance and what their permissions are on the target computer.
3) Tell me what user and TaskLogonType you are using when calling RegisterTaskDefinition and what their permissions are on the target computer.