Task Scheduler Actions

  • Imprimir
Este artigo ainda não foi traduzido.

Sometimes you may want to run a certain program on end user's computer, like for example invoke the TrueUpdate client software every 7 days or at each logon, without triggering the annoying UAC warning dialog. With the aid of the Task Scheduler, you can do so, but setting up new tasks is not very intuitive. This Lua script was written in an attempt to make the creation of new jobs in the Task Scheduler much easier while you are deploying your product.

How to use

  • Download the installer below and install the files in your Setup Factory folder. The installer will also allow the installation into the AutoPlay Media Studio folder, however the intended audience for this script are software publishers using Setup Factory.
  • For Setup Factory:
    Include the TaskScheduler.lua script file in your project, as shown in this image:

    For AutoPlay Media Studio:
    Copy TaskScheduler.lua from your AutoPlay Media Studio Gallery\Scripts sub folder to the AutoPlay\Scripts sub folder of your project's CD_Root. Then, in the On Startup script, place this code:

     
    require "TaskScheduler";
     

  • This script provides three functions: DoesJobExist allows you to check if a task exists with a certain name, CreateJob is used to schedule new tasks, while DeleteJob should be used to delete existing tasks, for example, when uninstalling the product.
  • Parameters used when creating new jobs:
    ParameterDescription
    User The user account for running the task. This can be the predefined account "System", or a user name like "John Doe".
    Password Password of the user account. The string entered here is ignored if the User was set to "System". Otherwise, if set to "*", the user will be prompted to provide the password for before the task is created. In most cases, it might be best if the password required to run the task is provided during the install, like shown in this sample screen:

    The example project below shows how you can capture the user name and display it in a read-only edit field.
    Schedule Defines when the task will be run. Can be one of these values: "ONLOGON", "ONIDLE", "ONSTART", "ONCE", "HOURLY" or "MINUTE".
    Modifier This number controls the behavior of the Schedule "HOURLY" and "MINUTE", for the other schedules this value is ignored. Setting the Modifier to 12 and selecting a "HOURLY" schedule would mean that the task is expected to run each 12 hours, while setting the Modifier to 30 and the Schedule to "MINUTE", the task would be run twice per hour.
    Taskname A string that specifies a unique identifier for the scheduled task.
    Filename A string that specifies the full path to the program that should be run at the scheduled time.
    Args A string that sets the optional command line argument for the task. This can be an empty string ("").
  • Here is a sample how you can check if a certain task exists, and in case it does not, create it (as you would typically do in the On Post Install script):
  •  
    if not TaskScheduler.DoesJobExist("MyTask") then
      -- schedule a silent update check at logon for my application
      -- the updater is best set to "silent until update is available"
      TaskScheduler.CreateJob("System", "(ignored)", "ONLOGON", 0, "MyTask", 
        SessionVar.Expand("%AppFolder%\\TrueUpdateClient.exe"), "/S");
      error = Application.GetLastError();
      if (error ~= 0) then
        Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
      else
        Dialog.Message("Info", "Task was created.", MB_OK, MB_ICONINFORMATION);
      end
    end
  • Here is a sample how you can check if a certain task exists, and in case it does, delete it (as you would do in the On Pre Uninstall script:
  •  
    if TaskScheduler.DoesJobExist("MyTask") then
      -- delete the existing task from the scheduler
      TaskScheduler.DeleteJob("MyTask");
      error = Application.GetLastError();
      if (error ~= 0) then
        Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
      else
        Dialog.Message("Info", "Task was deleted.", MB_OK, MB_ICONINFORMATION);
      end
    end

Please note that the process must be run with administrative privileges in order to create or delete jobs. Software installers are normally run as administrator, so this shouldn't be an issue, but remember this if you use this script in an AutoPlay project.

This work was tested on Windows XP, Vista and 7, and on both 32 and 64 bit platforms. It is expected to work correctly, however should you find any issue, please let me know using email or the contact form.

Full documentation of the Task Scheduler can be found at Microsoft, here. You can modify the script further, if you wish to. Redistribution without giving proper credits or as plugin is not permitted.

Download

Task Scheduler Actions for Setup Factory 9

Click to downloadFile size: 856 KB
Current version: 1.0.1.0
Updated: July 2013

Example project (Installer and source)

Click to downloadFile size: 2.20 MB
Updated: June 2011

Do you find this useful?

Several hours of work were invested into software offered on this site free of charge. If my efforts make your tasks easier and saved you hours of research and coding, please consider making a small donation as a sign of appreciation of my work, especially if you are using this in a commercial product. Thank you in advance for your support!

 

Our Plugins & Examples Feed

  • POP3 Actions plugin released

    A new, free actions plugin was released today. With it, the developer can check POP3...

  • Reminder: Update Serial Number Validation and/or Subscription Validation

    Next week IPInfoDB's API 2.0 will stop working. If you use an older version than...

Subscribe now!

Advertisement