Normally I would have posted this on StackOverflow, but it's currently down!

Normally I would have posted this on StackOverflow, but it's currently down!

Has anybody tried creating tasks using JEDI's TJclTaskSchedule?

The following code works perfectly on Windows 7 and earlier, but fails on Windows 8 with the error "The task XML is missing a required element or attribute". Anyone got any idea why?

unit Unit13;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,

  JclTask, MSTask;

type
  TForm13 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form13: TForm13;

implementation

{$R *.dfm}

procedure TForm13.Button1Click(Sender: TObject);
var
  TaskSchedule: TJclTaskSchedule;
  Task: TJclScheduledTask;
begin
  TaskSchedule := TJclTaskSchedule.Create('');
  try
    // This works on Windows 7 and earlier, but fails on Windows 8 with the error:
    // "The task XML is missing a required element or attribute"
    Task := TaskSchedule.Add(edtTaskname.Text);
  finally
    FreeAndNil(TaskSchedule);
  end;
end;

end.

Comments

  1. Sounds like the task XML which the JCL generates is not compatible with Windows 8 - i.e. missing a required field for Win8.

    Check specifications on MSDN and update JCL code?

    ReplyDelete
  2. Lars Fosdal - JCL doesn't generate the XML. It uses COM:

    procedure TJclScheduledWorkItem.Save;
    begin
      OleCheck((FScheduledWorkItem as IPersistFile).Save(nil, True));
    end;

    ReplyDelete
  3. That is strange... If MS obsoleted the COM interface, they must have screwed up.  If you export the specific com interfaces from a W7 vs a W8 machine - are there any differences?

    ReplyDelete
  4. TLama points out that v.1 of the interface is obsolete since Vista.  It's not unlikely that Windows 8 no longer supports it fully, and require v.2.

    ReplyDelete
  5. I think this must be the case. I think I'll convert my code to use schtasks.exe instead of relying on JEDI/COM.

    ReplyDelete
  6. How hard is it to export the v.2 IF ? I guess that will last a few years?  Calling an .exe file seems like a potential security issue.

    ReplyDelete
  7. At first glance, the V2.0 API looks a lot more involved than V1.0. How is calling the exe a security risk? It's a system file and any changes to the tasks require elevation.

    ReplyDelete
  8. In future, I'd post this on the Jedi Bug Tracker instead.

    ReplyDelete
  9. Warren Postma - I have already posted it on the JEDI bug tracker.

    ReplyDelete

Post a Comment