S h o r t S t o r i e s

// Tales from software development

WiX: Creating Scheduled Tasks

with 2 comments

The SCHTASKS command line program provides functions for creating and deleting scheduled tasks. It’s the quickest and easiest means to create a scheduled task as part of an install and the option I chose for the installer for the project I’m currently working on.

However, I’ve found that while creating a scheduled task is easy enough, deleting it during an uninstall is a little bit more complicated.

I defined two custom actions in the WiX file for the installer:

<CustomAction Id=”CreateFolderCleanerScheduledTask” Directory=”CLEANER_DIR” ExeCommand=””[SystemFolder]schtasks.exe” /Create /RU “[ScheduledTaskUsername]” /RP “[ScheduledTaskPassword]” /SC DAILY /MO 1 /ST 01:00:00 /TN “VitalData Folder Cleaner” /TR “\”[CLEANER_DIR]DailyClean.cmd\””” Execute=”commit” Return=”ignore” />

<CustomAction Id=”DeleteFolderCleanerScheduledTask” Directory=”CLEANER_DIR” ExeCommand=””[SystemFolder]schtasks.exe” /Delete /F /TN “VitalData Folder Cleaner”” Execute=”commit” Return=”ignore” />

The first custom action executed successfully during the install to create the scheduled task but the second failed with an odd message indicating that the program, presumably SCHTASKS, could not be found.

I got lucky when I guessed it was something to do with the Execute attribute. I changed it to “deferred” (on the second custom action only) and then the program executed successfully.

Now I just have to work out why that fixed the problem!


Written by Sea Monkey

October 8, 2009 at 6:00 pm

Posted in Deployment

Tagged with

2 Responses

Subscribe to comments with RSS.

  1. Did you ever figure out the problem here? I’m running into the same problem.

    Stephen E. Baker

    February 24, 2012 at 6:23 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: