WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: Ron47 on September 11, 2016, 01:34:08 PM

Title: Scheduling a task that runs on logon and then is repeated at set intervals
Post by: Ron47 on September 11, 2016, 01:34:08 PM
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?
Title: Re: Scheduling a task that runs on logon and then is repeated at set intervals
Post by: td on September 12, 2016, 07:17:57 AM
Delete the old task and create a new task.
Title: Re: Scheduling a task that runs on logon and then is repeated at set intervals
Post by: Ron47 on September 12, 2016, 08:53:54 AM
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.
Title: Re: Scheduling a task that runs on logon and then is repeated at set intervals
Post by: td on September 12, 2016, 10:29:42 AM
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.
Title: Re: Scheduling a task that runs on logon and then is repeated at set intervals
Post by: td on September 12, 2016, 01:21:33 PM
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 (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 (https://msdn.microsoft.com/en-us/library/aa383608(v=vs.85).aspx)
Title: Re: Scheduling a task that runs on logon and then is repeated at set intervals
Post by: Ron47 on September 13, 2016, 08:10:25 AM
Thanks. I'm looking at
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

I'm trying to figure how to create an onlogon trigger with this...
Title: Re: Scheduling a task that runs on logon and then is repeated at set intervals
Post by: td on September 13, 2016, 11:18:26 AM
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  (https://msdn.microsoft.com/en-us/library/aa381912(v=vs.85).aspx)
Title: Re: Scheduling a task that runs on logon and then is repeated at set intervals
Post by: Ron47 on September 14, 2016, 07:14:27 AM
That's what I needed. Thanks!