Recently one of our customers have asked if it is possible to create, within Advanced Installer, a Scheduled Task folder which would group more scheduled tasks.
Unfortunately, that is not currently possible. I have added it on our TODO list of improvements, but until this improvement will be added, let's discuss a bit how we can achieve this using a Custom Action - a PowerShell script to be more precise.
PowerShell, by default, does not have a CMDLET to create a Scheduled Task folder, but we can use Schedule.Service COM API.
From that, we will use the "TaskFolder object" which has the "CreateFolder" method.
Here's the logic we will be using for this:
- first of all, we will create the Schedule.Service object
- we will then connect to the schedule service
- we will then create the folder object
- and ultimately we will create the new folder
If we open PowerShell ISE (as administrator) and run the above and then open "Task Scheduler", the folder should be created there:
Code: Select all
# create the object $scheduleServiceObject = New-Object -ComObject schedule.service # connect to schedule service $scheduleServiceObject.connect() # target the root folder $rootFolder = $scheduleServiceObject.GetFolder("\") # create our folder $rootFolder.CreateFolder("testFolder")
To implement the above in Advanced Installer, we have to add a new "Run Inline PowerShell script" custom action and have that run the code from above:
Attached to this forum thread you can find a sample AIP which implements the above scenario.
Hope this helps!