Posts: 6739
Joined: Wed Jun 13, 2018 7:49 am

Use PowerShell to create Scheduled Task folders

Hello guys,

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

Code: Select all

# create the object
$scheduleServiceObject = New-Object -ComObject schedule.service
# connect to schedule service
# target the root folder
$rootFolder = $scheduleServiceObject.GetFolder("\")
# create our folder
If we open PowerShell ISE (as administrator) and run the above and then open "Task Scheduler", the folder should be created there:
Screenshot_131.png (106.92 KiB) Viewed 251445 times

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:
Screenshot_132.png (90.59 KiB) Viewed 251445 times

Attached to this forum thread you can find a sample AIP which implements the above scenario.
PowerShell Create Scheduled Task Folder Sample.aip
(14.56 KiB) Downloaded 2307 times

Hope this helps! :)

Best regards,
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Sample Projects”