janisito
Posts: 78
Joined: Thu Apr 09, 2015 6:28 am

Scheduled task that starts immediately and repeats

Fri Mar 08, 2019 5:01 pm

Hi,

How can I, using AI, create a scheduled task that starts after the installation has finished and repeats every 10 minutes and goes on forever? I can manually set this up in Windows but not sure how to do it through AI.
2.png
2.png (22.63KiB)Viewed 20567 times
Thx!

Regards
Jan

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: Scheduled task that starts immediately and repeats

Mon Mar 11, 2019 1:12 pm

Hello Jan,

Unfortunately, our "Scheduled Tasks" support does not support this. However, this can be achieved through a custom action (e.g. PowerShell script). Here is the little script which does that:

Code: Select all

$action = New-ScheduledTaskAction -Execute 'notepad.exe'
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 3)
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "TestTask" -Description "This is a test task. Its job is to start notepad every 3 minutes."
As you can see in the above script, the scheduled task will launch Notepad every 3 minutes. You may want to modify these options in order to match your needs.

Now, in order to configure this in your Advanced Installer project, please proceed as it follows:

- open your project and go to "Custom Actions" page

- add a "PowerShellInlineScript" with sequence. In order to do so, please press the "Add custom action with sequence" button which is placed to the right side of the custom action's name.

- copy paste the above script under the "Your code goes here." comment.

- the custom action should be scheduled after the "Add resources" action group and it should be configured as it follows:

Execution time: When the system is being modified (deferred)
The rest is default. Also, you may want to only trigger the custom action during the install. To do so, untick the "Uninstall" and "Maintenance" boxes from under the "Execution Stage Condition" section.

Also, one thing too keep in mind is the fact that, in order to create and register a scheduled task, you need elevated rights. With that being said, to avoid any unwanted behavior, please check the "Run as administrator" option from under the "Installation Options" section -> "Install Parameters" page.

Also, for your reference, I have attached a sample project to this thread:
Your Application.aip
(14.07KiB)Downloaded 266 times
Hope this helps.

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

janisito
Posts: 78
Joined: Thu Apr 09, 2015 6:28 am

Re: Scheduled task that starts immediately and repeats

Mon Mar 11, 2019 1:50 pm

Hi Catalin,

Thank you for your reply. I forgot to mention that the task should run regardless if the user is logged in or not. I noticed this script only runs when a user is logged in.

Regards
Jan

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: Scheduled task that starts immediately and repeats

Wed Mar 13, 2019 1:01 pm

Hello Jan,
Thank you for your reply.
You are always welcome.
I forgot to mention that the task should run regardless if the user is logged in or not. I noticed this script only runs when a user is logged in.
You are right, the task runs only when a user is logged in. In order to change this, we can add a scheduled task principal to our script using the "New-ScheduledTaskPrincipal" cmdlet. When you use a scheduled task principal, Task Scheduler can run the task regardless of whether that account is logged on.

With that being said, the earlier script now becomes:

Code: Select all

$action = New-ScheduledTaskAction -Execute 'notepad.exe'
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 3)
$principal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "TestTask" -Description "This is a test task. Its job is to start notepad every 3 minutes." -Principal $principal
Hope this helps.

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube


Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: Scheduled task that starts immediately and repeats

Tue Apr 02, 2019 9:22 am

You are always welcome, Jan.

Glad to help.

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”