2

I am using the Task Scheduler managed library available from https://taskscheduler.codeplex.com/.

I am trying to RegisterTask using the below code.

ts.RootFolder.RegisterTaskDefinition(Curr_Task.Name, Curr_Task.Definition, TaskCreation.CreateOrUpdate, str_username, str_password, TaskLogonType.Password);

But exception is thrown in the above line.

Error Code : -2147216615 Error Msg : (10,8):StartBoundary: Stack Trace as below :-

   at Microsoft.Win32.TaskScheduler.V2Interop.ITaskFolder.RegisterTaskDefinition(String Path, ITaskDefinition pDefinition, Int32 flags, Object UserId, Object password, TaskLogonType LogonType, Object sddl)
   at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition(String path, TaskDefinition definition, TaskCreation createType, String userId, String password, TaskLogonType logonType, String sddl) in D:\Jeet\Task Schedular API v2.5.22\Source Code\TaskService\TaskFolder.cs:line 424
   at SQScheduler.frmScheduleScenario.SetTriggerinTaskScheduler_New() in D:\Jeet\SQScheduler-branch_5.2\SQScheduler\Parameters\frmScheduleScenario.cs:line 1259

NOTE : For the first time when I call the RegisterTaskDefinition it works fine. But after updating the trigger, when it is called again the exception is thrown.

Update: The XML is as below:-

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2017-04-03T16:15:11.154+05:30</Date>
    <Description>Run parameters</Description>
  </RegistrationInfo>
  <Triggers>
    <TimeTrigger>
      <StartBoundary>2017-04-03T17:10:27.153</StartBoundary>
      <Enabled>true</Enabled>
    </TimeTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>FRSYMTRAX\JDoshi</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>LeastPrivilege</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <Duration>PT10M</Duration>
      <WaitTimeout>PT1H</WaitTimeout>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT2H30M</ExecutionTimeLimit>
    <Priority>10</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>D:\Program Files (x86)\Symtrax\StarQuery\Debug\SQSRunTime.exe</Command>
      <Arguments>"C:\ProgramData\Symtrax\SQScheduler\My Scenarios\New API Scenarios\Test\Test FTP.xml" "9384bea0-0f56-4423-b6f5-f22f51bf2378"</Arguments>
    </Exec>
  </Actions>
</Task>

Please suggest the changes required to get this working!!

JDoshi
  • 315
  • 4
  • 12
  • Actually the issue was with the `TriggerCollection.Add(Trigger t1)` of the library. It does not allow to `Add` the trigger again even after TriggerList has been cleared by calling `TriggerCollection.Clear()`. So managed with a workaround that does not call `Add` for 2nd time. – JDoshi Apr 04 '17 at 09:11
  • I have post the query to the forum, and will also post the answer here as I get later on. – JDoshi Apr 04 '17 at 10:06

1 Answers1

2

The error code -2147216615 that you're getting, if you convert it to Hexadecimal is 0x80041319, which is listed as SCHED_E_MISSINGNODE, meaning that "The task XML is missing a required element or attribute". Without seeing the XML I can't know what the problem is, but hopefully you should be able to work it out from that.

Richardissimo
  • 5,596
  • 2
  • 18
  • 36
  • Attached the XML. Plz check – JDoshi Apr 03 '17 at 11:44
  • What way you converted to Hex ?? Online decimal to hex converters are showing the different value. I tried on this [link](http://www.rapidtables.com/convert/number/decimal-to-hex.htm) . – JDoshi Apr 03 '17 at 12:00
  • I'm using Windows, so I start the calculator, switch to Programmer, in Decimal mode, paste the value, then switch to Hex and ignore the leading FFFFs. – Richardissimo Apr 03 '17 at 12:57
  • The schema I have is for version 1.3 (https://msdn.microsoft.com/en-us/library/windows/desktop/aa383609(v=vs.85).aspx), so it fails to validate this (which is version 1.2). – Richardissimo Apr 03 '17 at 12:58
  • 1
    @JDoshi have you tried importing your task XML directly into Task Scheduler? It might give you a more helpful error; or at least prove that the C# library is not part of the problem (I would expect that it is not part of the problem). There are instructions, and a version 1.2 example at http://www.authorcode.com/create-task-in-to-windows-task-scheduler-through-xml-file/ – Richardissimo Apr 04 '17 at 08:27
  • One other thought while I'm here... are you sure you should be using the version 1.2 schema? Perhaps it is expecting version 1.3. – Richardissimo Apr 04 '17 at 08:30
  • I am using 1.2 schema. Actually the managed library completely uses 1.2 schema to generate the XML. – JDoshi Apr 04 '17 at 09:03