Description
The win32-taskscheduler library is a Ruby interface to the MS Windows Task Scheduler. It is analogous to the Unix cron daemon.
Synopsis
require 'win32/taskscheduler'
include Win32
ts = TaskScheduler.new
# Create a trigger that starts on April 25, 2014 at 11:05 pm. The trigger
# will run on the first and last week of the month, on Monday and Friday,
# in the months of April and May.
#
trigger = {
:start_year => 2014,
:start_month => 4,
:start_day => 25,
:start_hour => 23,
:start_minute => 5,
:trigger_type => TaskScheduler::MONTHLYDOW,
:type => {
:weeks => TaskScheduler::FIRST_WEEK | TaskScheduler::LAST_WEEK,
:days_of_week => TaskScheduler::MONDAY | TaskScheduler::FRIDAY,
:months => TaskScheduler::APRIL | TaskScheduler::MAY
}
}
ts.new_work_item('foo', trigger)
ts.application_name = 'notepad.exe'
ts.save
Prerequisites
Ruby 1.8.2 or later. Building from source requires VC++ 6.0 or later. Windows XP or earlier. Vista and later not currently supported.
Installation
rake install (non-gem) OR rake install_gem (gem)
For most of you ‘gem install win32-taskscheduler’ will work.
Documentation
If you installed this library as a gem then the documentation was built for you and can be viewed if your gem server is running.
Otherwise, you can look at the doc/taskscheduler.txt file which should have everything you need.
Acknowledgements
This library was modeled to some degree on the Win32::TaskScheduler Perl module by Umberto Nicoletti. However, there are some differences. Please see the documentation for details.
On using OLE + WMI + Win32_ScheduledJob
I will probably include a pure Ruby version of this library at some point, and you can find what I have so far in CVS under lib/win32. Note, however, that there are some significant differences in behavior between the C library and WMI, along with limitations regarding modification to existing tasks.
You can find a list of differences here: tinyurl.com/2l3yau
Developer’s Notes
The CoInitialize() function is used internally instead of CoInitializeEx() function intentionally. The CoInitialize() function merely calls the CoInitializeEx() function with NULL and COINIT_APARTMENTTHREADED arguments, which is what we would do in any case.