BillStewart
Posts: 34
Joined: Sat Jul 28, 2007 1:48 am

Remove scheduled task based on condition

Hello,

I can see now that the scheduled task properties dialog now includes a condition field to create the task based on a condition. This is a very useful feature. Thank you for adding it.

However, I would like to also be able to remove the task based on a condition. The reason is that I have an installer that has a feature called ScheduledTask. I would like that if I install the feature, the task will be created, but if I uninstall the feature, the task will be removed. Any guidance on how to do this is appreciated.

Thanks,

Bill
BillStewart
Posts: 34
Joined: Sat Jul 28, 2007 1:48 am

Re: Remove scheduled task based on condition

Hi,

I have successfully created a custom action that executes a script to delete the .job file from the WindowsFolder\Tasks directory:

Code: Select all

var WindowsFolder = 0;
var FSO = new ActiveXObject("Scripting.FileSystemObject");
var CustomActionData = Session.Property("CustomActionData");

function deleteJob() {
  var jobfile, result;

  jobfile = FSO.BuildPath(FSO.BuildPath(FSO.GetSpecialFolder(WindowsFolder), "Tasks"), CustomActionData);
  result = 0;

  try {
    if (FSO.FileExists(jobfile))
      FSO.DeleteFile(jobfile);
  }
  catch(err) {
    result = err.number;
  }

  return result;
}
I placed this script in InstallExecuteSequence->Install and it runs deferred with no impersonation. The action data field is filled in with the job file's name, and the CA's condition is ((&ScheduledTask=2) And (!ScheduledTask=3)) meaning the CA will run when the ScheduledTask feature is being uninstalled. The script works, and deletes the task when the feature is removed.

However, if I run the installer again and reselect the feature, the scheduled task is not recreated. The condition for the scheduled task is: &ScheduledTask=3 -- which I thought is supposed to mean "create the task if the ScheduledTask is set to be installed."

It appears that the scheduled task condition only works during the first install, but not for a modify or repair. Any advice or assistance is appreciated.

Thanks,

Bill
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Re: Remove scheduled task based on condition

Hi,

I'm afraid repairing a scheduled task is not yet supported. I have added this on our TODO list and will be available in the next version of AI.

Best Regards,
Gigi
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com/
BillStewart
Posts: 34
Joined: Sat Jul 28, 2007 1:48 am

Re: Remove scheduled task based on condition

Hi,

I guess the feature I'm really looking for is a way for a scheduled task to be a component. That way it can be included in a feature, installed or removed, etc.

Thanks!

Bill
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Re: Remove scheduled task based on condition

Hi,
I guess the feature I'm really looking for is a way for a scheduled task to be a component. That way it can be included in a feature, installed or removed, etc.
I have added this on our TODO list and will be available in a future version of AI. Thank you for your suggestion.

Regards,
Gigi
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com/

Return to “Common Problems”