Scheduling a task that runs on logon and then is repeated at set intervals

Started by Ron47, September 11, 2016, 01:34:08 PM

Previous topic - Next topic

Ron47

I'd like to create a task that runs on logon and then is repeated at set intervals.

But I am unable to find a way to do this by using a command line:

ShellExecute('schtasks', '/Create  /SC ONLOGON /TN "atest" /TR "%executablename%"', '', @NORMAL, '')

Because if you create a task that runs on ONLOGON you can't set /RI.
(from http://www.robvanderwoude.com/schtasks.php
/RI interval   Specifies the repetition interval in minutes.
This is not applicable for schedule types: MINUTE, HOURLY, ONSTART, ONLOGON, ONIDLE, ONEVENT.)


As as workaround, I created the task with an xml file.

ShellExecute('schtasks', '/Create /TN "atest" /XML "%xmlfile%" ', '', @NORMAL, '')

But, users want to be able to change the intervals at which the task is run, which brings me back to wanting to be able to create or change a task that runs on logon and then is repeated at intervals using ShellExecute('schtasks' or ...

Any ideas?

td

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

Ron47

Yes, that's what I'm doing. I have a dialog that lets the user change the Interval value then I replace the old value in the xml file, delete the old task and create a new one with the updated xml file.
I'm just hoping that there's a cleaner way of doing this.

td

Microsoft has full documentation for the command line Task Scheduler tool and the Task Scheduler XML schema.  You could try staring at that for awhile.  Otherwise, sanitary computing while desirable is not always attainable.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

Didn't mention this before because I mistakenly thought it wasn't supported anymore and not sure if this will do exactly what you want but there is the 'Schedule.Service' COM Automation object for creating and perhaps modifying scheduled tasks. More can be found here:

http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP/Task~Scheduler+Create~a~Daily~Scheduled~Task.txt

and here:

https://msdn.microsoft.com/en-us/library/aa383608(v=vs.85).aspx
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade


td

There is an interface in the type library for the COM Automation object that is specifically for logon triggers and the MSFT documentation has at least one VB examples that is relatively easy to translate into WinBatch.

https://msdn.microsoft.com/en-us/library/aa381912(v=vs.85).aspx
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade