Allow2010 Posted December 26, 2011 Share Posted December 26, 2011 (edited) Hi all,i needed an UDF for using the Windows Taskplaner / Task Scheduler.Everything i found wasbased on at.exe (outdated) orbased on schtasks.exe (limited in functionality) orusing 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#post214517But 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 bugsEdit3: 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 3.3.9.4 or newer) - see this post for details: (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 $starwhenavailableEdit8: added version 5.3 fixed versioncompare problems and some typos (now runs with latest beta 3.3.9.22)Edit9: added version 5.4 (the COM errorhandler is back :-))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) No longer true - use lates version with errorhandlerNow we have:Func _TestTaskSchedulerUDF()Func _TaskSchedulerAutostart();check if the schedulerservice is set to autostartFunc _TaskIsValidPlatfrom() ;check if os and autoit versions are OK for use with this udfFunc _TaskFolderCreate($folder);Create folder - only folders that do not already exist can be created without errorFunc _TaskFolderDelete($folder);Delete folder - only folders that do exist and that are empty can be deleted without errorFunc _TaskFolderExists($folder = "");check if a TaskFolder existsFunc _TaskExists($taskname, $folder = "");check if a Task existsFunc _TaskStop($taskname, $folder = "");stop a taskFunc _TaskStart($taskname, $folder = "");start a taskFunc _TaskIsRunning($taskname, $folder = "");check if a Task is runningFunc _TaskIsEnabled($taskname, $folder = "");check if a Task is enabledFunc _TaskEnable($taskname, $folder = "");Enable TaskFunc _TaskDisable($taskname, $folder = "");Disable TaskFunc _TaskDelete($taskname, $folder = "");delete an existing taskFunc _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)taskplanerCOMneh5.2.ziptaskplanerCOM_neh5.3.zip taskplanerCOM_5.4.zip Edited October 7, 2015 by Allow2010 AvvA, ModemJunki and mLipok 3 Link to comment Share on other sites More sharing options...
ChrisN Posted December 26, 2011 Share Posted December 26, 2011 This topic should probably be in the Example Scripts forum, not the ActiveX/COM Help and Support forum. P.S. I don't have vista so I can't test it Link to comment Share on other sites More sharing options...
Allow2010 Posted December 26, 2011 Author Share Posted December 26, 2011 (edited) as this is very fresh and i could very well need some help to improve it, i think it is no yet ready to be an example-)>WinVista or higher is required.>>P.S. I don't have vista so I can't test ithmm, but you probaly have something newer than Vista? Or are you still running W2000/9x? Edited December 26, 2011 by Allow2010 Link to comment Share on other sites More sharing options...
ChrisN Posted December 26, 2011 Share Posted December 26, 2011 hmm, but you probaly have something newer than Vista? Or are you still running W2000/9x?Nope. WinXP Link to comment Share on other sites More sharing options...
Allow2010 Posted December 27, 2011 Author Share Posted December 27, 2011 :-) Forgot about XP:-) Well the COM based method is (IMHO) the best solution as long as no os support below Vista is needed. I could not find a solution that offers the same possibillities on all OS version. Link to comment Share on other sites More sharing options...
Allow2010 Posted December 27, 2011 Author Share Posted December 27, 2011 Update: added more functions to first post Link to comment Share on other sites More sharing options...
Allow2010 Posted December 30, 2011 Author Share Posted December 30, 2011 (edited) as i noticed the code is a bit stupid:-) If one function fails, every function returns a failure...will fix that and post a new version... Edited November 24, 2012 by Allow2010 Link to comment Share on other sites More sharing options...
Allow2010 Posted December 30, 2011 Author Share Posted December 30, 2011 This page here http://msdn.microsoft.com/en-us/library/windows/desktop/aa381341%28v=VS.85%29.aspx tells me that i can get a returncode Return value If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. but $result = $oFolder.CreateFolder($folder) seems to return [out] ITaskFolder **ppFolder so any idea how i can get the return code? Thanks ! Link to comment Share on other sites More sharing options...
Allow2010 Posted December 30, 2011 Author Share Posted December 30, 2011 updates udf in first post. fixed bugs, changed some names and comments my question above is still open...help from some com professional is welcome.-) Link to comment Share on other sites More sharing options...
Allow2010 Posted December 31, 2011 Author Share Posted December 31, 2011 Updated first post with some info and updated UDF (changed parameter help only) Link to comment Share on other sites More sharing options...
KaFu Posted December 31, 2011 Share Posted December 31, 2011 Looks really nice ! And yeah, maybe a Mod better moves this to the example forum. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 1, 2012 Moderators Share Posted January 1, 2012 Allow2010, Do you want it moved? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Allow2010 Posted January 1, 2012 Author Share Posted January 1, 2012 as i am not sure if it is good enough to be an example, its up to you.-) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 1, 2012 Moderators Share Posted January 1, 2012 (edited) Allow2010, You will get many more hits here - could help you make it even better. M23 Edited January 1, 2012 by Melba23 Wrong button too soon! Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Allow2010 Posted January 3, 2012 Author Share Posted January 3, 2012 (edited) added new version to first post with some bugfixes/changes for latest AutoIt version Edited January 3, 2012 by Allow2010 Link to comment Share on other sites More sharing options...
NDog Posted April 19, 2012 Share Posted April 19, 2012 (edited) I am impressed with your UDF and I think it is much better than schtasks.exeI want to create a daily task, whichstarts at 6:30repeats every 6 hours, for a duration of one dayAt the moment I can create a daily task which starts at 6:30, repeats every 6 hours but indefinately. I would like to change that to a duration of one day if possible?_TaskCreate("Smart-Net\SmartRAS Monitor Script", "Report in info about the Smart-RAS to SNID", 2, "2000-01-01T06:30:00", "", "", "", "", "", 1, "PT6H", True, 1, 0, $username,$password, """"&$app&"""", "", "", False, True,0,True,True,False,False,False,"P3D",5)EDITHave modified the UDF to support $DurationIf $RepetitionEnabled Then $oTriggerRepetition = $oTrigger.Repetition() $oTriggerRepetition.Interval() = $Interval $oTriggerRepetition.Duration() = $Duration EndIfNow I am running this code to do what I need_TaskCreate("Smart-Net\SmartRAS Monitor Script", "Report in info about the Smart-RAS to SNID", 2, "2000-01-01T06:30:00", "", "", "", "", "", 1, "PT6H","P1D", True, 1, 0, $username,$password, """"&$app&"""", "", "", False, True,0,True,True,False,False,False,"P3D",5)Thanks for the code, its extremely useful. BTW if others want to modify the code I recommend using powershell script here to enumerate the schedule task objects Edited April 19, 2012 by NDog Link to comment Share on other sites More sharing options...
Allow2010 Posted April 23, 2012 Author Share Posted April 23, 2012 thanks...good addition... Link to comment Share on other sites More sharing options...
martin Posted April 23, 2012 Share Posted April 23, 2012 Looks like a useful UDF Allow2010. Thanks A very small suggestion: The _TaskCreate function has a dayof month parameter which has to be some power of 2. It would be easier (for me at least) if this parameter were just the actual day of the month. To keep it compatible with previous versions you could say that if a negative value is used it means the actual day number (1 - 31). Use -32 for "last day". Then in the function you could have if $DaysOfMonth < 0 then $DaysOfMonth = 2^(-$DaysOfMonth - 1) Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
guinness Posted May 17, 2012 Share Posted May 17, 2012 (edited) Just came across this today and have to say very impressive. Thanks for posting it. There is room for improvement e.g. _TaskSchedulerAutostart() can be consolidated into one line or three if you count Func and EndFunc. Func _TaskSchedulerAutostart() Return RegRead("HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesSchedule", "Start") > 0 ; Returns True or False. EndFunc ;==>_TaskSchedulerAutostart Edited May 17, 2012 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Attckdog Posted July 9, 2012 Share Posted July 9, 2012 Thanks for this, I have been using it successfully wish a few more options were there tho A true renaissance man Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now