[Win32utils-devel] Implementing a TaskScheduler#exists? method

Daniel Berger djberg96 at gmail.com
Fri Jun 19 16:52:07 EDT 2009


Hi,

<snip>

> > Ok, how would you like to proceed? Should I release the current (pure
> Ruby) code with a warning regarding Vista or later? Or wait?
> >
> Good news is Task Sheduler 2.0 fully supports Scripting.
> Thus an implementation using win32ole is easy.
> 
> Here is a sample for enumerating tasks:
> 
> #---------------------------------------------------------
> # This sample enumerates through the tasks on the local computer and
> # displays their name and state.
> #---------------------------------------------------------
> require 'win32ole'
> 
> # Create the TaskService object.
> service =  WIN32OLE.new("Schedule.Service")
> service.Connect()
> 
> # Get the task folder that contains the tasks.
> rootFolder = service.GetFolder("\\")
> 
> taskCollection = rootFolder.GetTasks(0)
> 
> numberOfTasks = taskCollection.Count
> 
> if numberOfTasks == 0
>     puts "No tasks are registered."
> else
>     puts "Number of tasks registered: #{numberOfTasks}"
> 
>     taskCollection.each do |registeredTask|
>         puts "Task Name: #{registeredTask.Name}"
> 
>         case registeredTask.State
>             when "0"
>                 taskState = "Unknown"
>             when "1"
>                 taskState = "Disabled"
>             when "2"
>                 taskState = "Queued"
>             when "3"
>                 taskState = "Ready"
>             when "4"
>                 taskState = "Running"
>         end
> 
>         puts "    Task State: #{taskState}"
>     end
>   end

Ok, cool. I went ahead and released 0.2.0 without Vista support for now. Version 0.3.0 will support Vista and use win32ole behind the scenes.

Regards,

Dan



More information about the win32utils-devel mailing list