i needed an UDF for using the Windows Taskplaner / Task Scheduler.
Everything i found was
- based on at.exe (outdated) or
- based on schtasks.exe (limited in functionality) or
- using WMI (which can not see task that were not created with WMI and is also limited)
The only good solution i found was here: http://www.autoit.de/index.php?page=Thread&postID=214517#post214517
But it only had a Create Function.
With my limited knowledge i tried creating more functions and it seems to work quite OK.
You can try it out with TestTaskSchedulerUDF(). WinVista or higher is required.
All feedback is welcome, but please be kind, i do not have much practise and i am well aware that there is room for improvment.
Edit: added new version of the code with more functions:
Edit2: updated UDF fixed bugs
Edit3: added info for multiinst parameter (_TaskCreate)
Edit4: updated UDF (some bugfixes)
Edit5: added version info to UDF, added changes/additions suggested in this thread (_TaskIsEnabled(), _TaskEnable(), _TaskDisable() and $duration for _TaskCreate())
Edit6: added new version that does not use a COM errorhandler (this version can be mixed with other com functions with or without errorhandler, but requires current autoit beta 22.214.171.124 or newer) - see this post for details: http://www.autoitscript.com/forum/topic/138279-com-error-handler-return-values/#entry968768 (if you do not need other COM routines, there is no need to change from the last version to this one, but all newer version will be without errorhandler...)
Edit7: added version 5.2 with new TaskCreate option $starwhenavailable
Edit8: added version 5.3 fixed versioncompare problems and some typos (now runs with latest beta 126.96.36.199)
As long as there is no feedback this will be the last update...for me it works like it should and i can manage all my tasks just fine!
Keep in Mind that Autoit does not support using more than one ComError Function so be careful if you use other com udfs that need a com errorfunction - this is not a problem when using the taskplanerCOMneh.au3 version (neh=no error handler)
Now we have:
- Func _TestTaskSchedulerUDF()
- Func _TaskSchedulerAutostart();check if the schedulerservice is set to autostart
- Func _TaskIsValidPlatfrom() ;check if os and autoit versions are OK for use with this udf
- Func _TaskFolderCreate($folder);Create folder - only folders that do not already exist can be created without error
- Func _TaskFolderDelete($folder);Delete folder - only folders that do exist and that are empty can be deleted without error
- Func _TaskFolderExists($folder = "");check if a TaskFolder exists
- Func _TaskExists($taskname, $folder = "");check if a Task exists
- Func _TaskStop($taskname, $folder = "");stop a task
- Func _TaskStart($taskname, $folder = "");start a task
- Func _TaskIsRunning($taskname, $folder = "");check if a Task is running
- Func _TaskIsEnabled($taskname, $folder = "");check if a Task is enabled
- Func _TaskEnable($taskname, $folder = "");Enable Task
- Func _TaskDisable($taskname, $folder = "");Disable Task
- Func _TaskDelete($taskname, $folder = "");delete an existing task
- Func _TaskListall($folder = "", $hidden = 1);get a list of all tasks in a given taskfolder (Tasknames only) List is a string with names separeted by "|"
- Func _TaskCreate($taskname, $TaskDescription, $TriggerEvent, $StartTrigger, $EndTrigger, $DaysOfWeek, $DaysOfMonth, $MonthOfYear, $WeeksOfMonth, $DaysInterval, $Interval, $RepetitionEnabled, $LogonType, $RunLevel, $Username, $Password, $Program, $WorkingDirectory = "", $Arguments = "", $RunOnlyIfNetworkAvailable = True, $active = True, $multiinst = 0, $nobatstart = False, $stoponBat = False, $hidden = False, $idle = False, $WakeToRun = False, $timelimit = "P1D", $priority = 5, $duration="", $StartWhenAvailable = True)
Edited by Allow2010, 09 November 2013 - 09:25 PM.