task - delphi ITaskFolder.RegisterTaskDefinition not working -


i'm trying create task windows task scheduler. here's code.

procedure tform1.button1click(sender: tobject); var   ts: itaskservice;   tf: itaskfolder;   tf2: itaskfolder;   td: itaskdefinition;   tr: itrigger;   tt: itimetrigger;   at: iaction;   ae: iexecaction;   rt: iregisteredtask; begin   coinitializeex(nil, coinit_multithreaded);         cocreateinstance(clsid_taskscheduler,nil,clsctx_inproc_server,iid_itaskservice,ts);   ts.connect(unassigned, unassigned, unassigned, unassigned);   try     tf := ts.getfolder('\myfolder');     tf2 := tf;   except     tf := ts.getfolder('\');     tf2 := tf.createfolder('\myfolder', unassigned);   end;   tf._release;   td := ts.newtask(0);   td.registrationinfo.author := 'theauthor';   tr := td.triggers.create(tttime);   tr.queryinterface(iid_itimetrigger, tt);   tr._release;   tt.id := 'trigger1';   tt.startboundary := '2017-07-28t01:20:00';   tt.endboundary := '2027-07-28t01:20:00';   tt._release;   @ := td.actions.create(taexec);   at.queryinterface(iid_iexecaction, ae);   at._release;   ae.path := 'c:\windows\system32\notepad.exe';   ae.workingdirectory := 'c:\windows\system32';   ae.arguments := '--help';   ae._release;   rt := nil;   rt := tf2.registertaskdefinition('mytesttask', td, 1, unassigned, unassigned, tlinteractivetoken, '');   rt._release;   td._release;   tf2._release;   couninitialize; end; 

it works fine until registertaskdefinition method. returns nil , think it's error cause no task created in directory in c:\windows\system32\tasks. directory myfolder creating properly. can't define error type cause there no error codes returning in delphi version of taskscheduler api 2.0. seems parameters of function correct continues return nil instead of iregisteredtask object. maybe forgot something, or doing wrong? work on windows 7 , delphi xe 10.2. uac turned off.

you calling registertaskdefinition method task_validate_only flag. flag described like:

task_validate_only

task scheduler verifies syntax of xml describes task, does not register task. constant cannot combined task_create, task_update, or task_create_or_update values.

so call returns null pointer in pptask parameter because no task has been registered. if weren't using magic constants , use proper defined constants task_create instead of 2 (or task_validate_only instead of 1), find problem pretty simply.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -