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

// Tales from software development

Archive for October 2009

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

The generator failed while calculating the amount of time to sleep until the next quantum ends

with one comment

I’m writing an interface for an application that needs to work with a clinical health system that uses Microsoft SQL Server Notification Services. A few weeks ago I started up the virtual machine that has a copy of the clinical health system installed on it and noticed that one of its services had failed to start. Repeated attempts to start it failed and when I looked in the event log I saw this cryptic error message from SQL Server Notification Services:

The generator failed while calculating the amount of time to sleep until the next quantum ends.

For once, Google didn’t provide any useful links that might shed some light on the problem or explain how to resolve it. Fortunately, the technical guys at the company that develops the clinical health system had seen the problem previously and were able to tell me how to resolve it.

The problem arises when Notification Services hasn’t been running for more than 20 days and 20 hours because the calculation it uses to determine how long it is since it was last ran overflows when the elapsed time is greater than this. Seems like Microsoft didn’t test this bit of Notification Services very rigorously.

The solution to get Notification Services started again is:

  • Ensure that all Notification Services applications (usually services) are stopped.
  • Run the NSSetQuantumClockDate stored procedure in each database that uses Notification Services specifying the date and time from which notifications should be processed.
  • Restart the Notifications Services applications.
  • Check that the services all restarted successfully and check the event log to confirm that the problem has been resolved.

Written by Sea Monkey

October 5, 2009 at 7:00 pm