Windows Task Scheduler API
Has anyone done any work with the above API?
I have imported the Automation classes and have this working all the way till the last bit with is the task registration
It fails and return a NULL variant but no errors.
the function in question is
[CODE]
// Create new task.
Function ComRegisterTaskDefinition String llPath Variant llpDefinition Integer llflags Variant llUserId Variant llpassword OLE_TASK_LOGON_TYPE llLogonType Variant llsddl Returns Variant
Handle hDispatchDriver
Variant retVal
Get phDispatchDriver to hDispatchDriver
Send PrepareParams to hDispatchDriver 7
Send DefineParam to hDispatchDriver OLE_VT_BSTR llPath
Send DefineParam to hDispatchDriver OLE_VT_DISPATCH llpDefinition
Send DefineParam to hDispatchDriver OLE_VT_I4 llflags
Send DefineParam to hDispatchDriver OLE_VT_VARIANT llUserId
Send DefineParam to hDispatchDriver OLE_VT_VARIANT llpassword
Send DefineParam to hDispatchDriver OLE_VT_I4 llLogonType
Send DefineParam to hDispatchDriver OLE_VT_VARIANT llsddl
Get InvokeComMethod of hDispatchDriver 11 OLE_VT_DISPATCH to retVal
Function_Return retVal
End_Function
[/CODE]
no matter what I call this with I cannot get a successful result. All permutations of allowable value etc fails
[CODE]
Get ComRegisterTaskDefinition of hoFolder 'MyTask' vTaskDefinition OLETASK_CREATE_OR_UPDATE vUserId vPassword OLETASK_LOGON_INTERACTIVE_TOKEN_OR_PASSWORD OLE_VT_Empty to vTask
[/CODE]
A broad question but I figure someone may have done this
Re: Windows Task Scheduler API
I will have a look for you tomorrow
Re: Windows Task Scheduler API
Thanks
Wasted a whole weekend on this last part
Aaargh
Re: Windows Task Scheduler API
This is what we use for unattended tasks
[code]
Get ComRegisterTaskDefinition of oFolder tSchedule.sTaskName vCom OLETASK_CREATE_OR_UPDATE tSchedule.sUserId tSchedule.sPassword OLETASK_LOGON_PASSWORD Nothing to vCom
[/code]
There are certainly plenty of quirks with the whole process like not being allowed to edit an existing task setup directly in the scheduler is one case where you would get a null handle back
This long thread might have a clue to your issue but it's probably something simple in the task details you have setup
[url]https://social.msdn.microsoft.com/Forums/en-US/4a0dd24b-11fe-47e7-9d76-f24a6fe1b4d8/update-a-windows-scheduled-task-on-windows-10-not-working?forum=vcgeneral&prof=required[/url]
Things like if you are using Repetition the duration must be longer than then interval
I assume you have checked if the task already exists and if not called ComNewTask first ?
What sort of other things are you setting in the other collections before registering the task ?
Re: Windows Task Scheduler API
Hi
It seems to be some weird rights issue. I agree this API is very quirky.
Even though I am a system admin it was some weird voodoo going on. Not 1005 confident as yet if it sorted to my satisfaction to unleash in the wild!
Re: Windows Task Scheduler API
[URL="https://docs.microsoft.com/en-us/windows/win32/taskschd/taskfolder-registertaskdefinition"]TaskFolder.RegisterTaskDefinition method - Win32 apps | Microsoft Docs[/URL]
Not sure if this helps but read at the bottom regarding return value.
Re: Windows Task Scheduler API
Hi Chris
Have you considered using a powershell script?
Re: Windows Task Scheduler API
Saw as an option but didnt investigate