Jump to content

Would you like to see a brushed up Task Scheduler UDF (inlcuding help files, examples ...)?  

39 members have voted

  1. 1. Would you like to see such a brushed up UDF?

    • Yes
    • Don't mind
    • Maybe later
      0
    • No
      0


Recommended Posts

Posted

Thanks water.  My theory why it works this way is the task definition object is not assigned to a task until it is registered.  So when you use the task object to get the task definition object, it is the definition of when it was last registered.  If you changed the task definition object, but not register it again, it just changes it for that particular task definition object.  You could get the definition again to a different task definition object, and make different changes to it.  You would then have two definitions for the same task, but only the one registered would keep the changes.  That is how I see it anyway.  Why it was done this way?  Only MS knows.    

 

Adam

Posted

All object models of Microsoft products I have worked with have a "hierarchy" of objects.
An Excel Workbook is the parent of a Worksheet is the parent of a Range ... Means: You have to define a Workbook before you can define a Worksheet before you can define a Range ... That's why this objects can provide a "parent" property.

The Task Scheduler object model does not provide "parent" properties, just methods and further properties. So I think the map of the object model I have drawn in the wiki might not be fully correct. That would explain why it doesn't behave as expected. As Microsofts documentation and sources on the web do not explain it in depth I think we will have to live with what we have :)

WIll release an updated version quite soon :)
 

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Version 1.5.1.0 released

Changelog can be found on the download page and the history in the ZIP file.

For download please see my signature below.

Please play with this version and tell me what doesn't work or is missing!

My UDFs and Tutorials:

  Reveal hidden contents

 

  • 2 weeks later...
Posted (edited)

With version 1.4.0.0 function _TS_TaskValidate to check the task Definition for errors before Registration has been added.
A few checks have already been implemented but I'm sure there are more sensible checks to be done.

Which problems did you find when working with the UDF?
Could this problems be found by _TS_TaskValidate?

Please let me know so I can add them to the function!

Edited by water

My UDFs and Tutorials:

  Reveal hidden contents

 

  • 3 weeks later...
Posted

Anyone?

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Hi water,

I got caught up on some year end server migration projects, and then winter break.  I did some testing of _TS_TaskValidate, but not a whole lot.  I didn't find any issues with the tests I have done.   I plan on testing some more, after server migrations are completed.  

 

Adam

 

Posted

Hi Adam,

I hope you had a great Xmas vacation and a good start into 2020!

The _TS_TaskValidate function is just a sceleton for more tests to be done to make sure _TS_TaskRegister runs without errors.
Currently all problems I did find on the forum get checked. But I'm sure there are more ... :)

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

The example scripts that come with the UDF have full blown error checking included.

My UDFs and Tutorials:

  Reveal hidden contents

 

  • 3 months later...
Posted

Hi Water, I'm using this to create a scheduled task from a previously exported XML and was working great using a test script, but when trying to implement into my main script it is failing every time with a COM error.

Turns out, it was because I am using a custom error handler for my DB connections which is interfering with the _TS_Open() > _TS_ErrorNotify(4)

Global $iEventError = 0             ;Checks for COM errors
Global $oMyError = ObjEvent("AutoIt.Error", "ErrFunc") ;Install a custom error handler for any DB connection issues


Global $oService = _TS_Open()
If @error <> 0 Then Exit MsgBox($MB_ICONERROR, "Task Scheduler UDF", "Error connecting to the Task Scheduler Service. @error = " & @error & ", @extended = " & @extended & @CRLF & @CRLF & _TS_ErrorText(@error))


Func ErrFunc()
    ConsoleWrite("We intercepted a COM Error !" & @CRLF & _
                "Number: 0x" & Hex($oMyError.number, 8) & @CRLF & @TAB & _
                "Description: " & $oMyError.windescription & @CRLF & @TAB & _
                "At line: " & $oMyError.scriptline & @CRLF)
    $iEventError = 1                                                                                ; Use to check when a COM Error occurs
EndFunc   ;==>ErrFunc

Returns:  Error connecting to the Task Scheduler Service.  error = 101, extended = 203, _TS_Open(101):  Error reating the COM error handler.  extended is set to the error code returned by _TS_ErrorNotify

 

Is there a way to modify the TaskScheduler.au3 to use my custom error handler?

Thanks,

Mike

Posted (edited)

You could call _TS_ErrorNotify(2) before calling _TS_Open to get detailed error information.

Or you create your custom COM error handler after _TS_Open.

Edited by water

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Well, this is getting complicated as I need #RequireAdmin for this, but as I'm building this into an installer.  if I copy my files over while under #RequireAdmin it then prompts for Admin UAC every time I run the files that were copied over that way.

 

Ugh.  I think I'm going to split this Task Create part into a separate .a3x file and run using a ShellExecute after I create the .xml from the initial setup script.  That way I don't need to worry about the COM error handler.

  • 1 month later...
Posted

_TS_Wrapper_TriggerDateTime should do what you are looking for.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

I have manually created a task with your specifications and get the following XML (part of the full task definition) for the trigger:

  Quote

  <Triggers>
    <TimeTrigger>
      <Repetition>
        <Interval>PT15M</Interval>
        <Duration>P1D</Duration>
        <StopAtDurationEnd>false</StopAtDurationEnd>
      </Repetition>
      <StartBoundary>2020-06-06T13:00:00</StartBoundary>
      <Enabled>true</Enabled>
    </TimeTrigger>
  </Triggers>

Expand  

You could now use one of the ways described in the wiki to create a task with the UDF.

My UDFs and Tutorials:

  Reveal hidden contents

 

  • 2 months later...
Posted (edited)

Hey @water,

First time testing this UDF and I am having issues getting started. I keep getting many "'With' cannot be nested." Errors.

Simple Code:

#include <TaskScheduler.au3>

Global $oService = _TS_Open()

Errors:

  Reveal hidden contents

With so many people being able to run this without issues, I am thinking it's some setting in my AutoIT I need to change?

Let me know what you think!

UDF Version: 1.5.1.0

Thanks.

Edited by Davidowicza
Posted

Seems you are running a quite old version of AutoIt:

3.3.12.0 - 1st June, 2014

Is it possible to update to the latest production release?
According to the history file a few issues with "With/EndWith" have been fixed.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Looks like when we got our new PCs a couple months ago I focused on updating the SciTE rather than Autoit itself.... don't mind me I'll be in the corner :whistle:

Thanks, haha.

  • 2 months later...
Posted

hm...

  Quote

; Modified.......: 20201123 (YYYYMMDD)

Expand  

Quite interesting date ..... ;)

But seriously:
Could you add this:
 

; Forum link ....: https://www.autoitscript.com/forum/files/file/487-task-scheduler/
; Forum link ....: https://www.autoitscript.com/forum/topic/200068-creating-a-brushed-up-task-scheduler-udf/

to the header ?

When I download UDF form forum or some form github, after few years when I sombody want to check whats new then this information could be very handy, in each UDF

Oops... I should change couple of my own :)

 

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...