Class: Win32::TaskScheduler
- Inherits:
-
Object
- Object
- Win32::TaskScheduler
- Includes:
- Windows::TaskSchedulerHelper
- Defined in:
- lib/win32/taskscheduler.rb
Overview
The TaskScheduler class encapsulates a Windows scheduled task
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
The version of the win32-taskscheduler library
'0.3.2'.freeze
- TASK_TIME_TRIGGER_ONCE =
Trigger is set to run the task a single tim
0- TASK_TIME_TRIGGER_DAILY =
Trigger is set to run the task on a daily interval
1- TASK_TIME_TRIGGER_WEEKLY =
Trigger is set to run the task on specific days of a specific week & month
2- TASK_TIME_TRIGGER_MONTHLYDATE =
Trigger is set to run the task on specific day(s) of the month
3- TASK_TIME_TRIGGER_MONTHLYDOW =
Trigger is set to run the task on specific day(s) of the month
4- TASK_EVENT_TRIGGER_ON_IDLE =
Trigger is set to run the task if the system remains idle for the amount of time specified by the idle wait time of the task
5- TASK_EVENT_TRIGGER_AT_SYSTEMSTART =
Trigger is set to run the task at system startup
6- TASK_EVENT_TRIGGER_AT_LOGON =
Trigger is set to run the task when a user logs on
7- TASK_SUNDAY =
The task will run on Sunday
0x1- TASK_MONDAY =
The task will run on Monday
0x2- TASK_TUESDAY =
The task will run on Tuesday
0x4- TASK_WEDNESDAY =
The task will run on Wednesday
0x8- TASK_THURSDAY =
The task will run on Thursday
0x10- TASK_FRIDAY =
The task will run on Friday
0x20- TASK_SATURDAY =
The task will run on Saturday
0x40- TASK_FIRST_WEEK =
The task will run between the 1st and 7th day of the month
1- TASK_SECOND_WEEK =
The task will run between the 8th and 14th day of the month
2- TASK_THIRD_WEEK =
The task will run between the 15th and 21st day of the month
3- TASK_FOURTH_WEEK =
The task will run between the 22nd and 28th day of the month
4- TASK_LAST_WEEK =
The task will run the last seven days of the month
5- TASK_JANUARY =
The task will run in January
0x1- TASK_FEBRUARY =
The task will run in February
0x2- TASK_MARCH =
The task will run in March
0x4- TASK_APRIL =
The task will run in April
0x8- TASK_MAY =
The task will run in May
0x10- TASK_JUNE =
The task will run in June
0x20- TASK_JULY =
The task will run in July
0x40- TASK_AUGUST =
The task will run in August
0x80- TASK_SEPTEMBER =
The task will run in September
0x100- TASK_OCTOBER =
The task will run in October
0x200- TASK_NOVEMBER =
The task will run in November
0x400- TASK_DECEMBER =
The task will run in December
0x800- TASK_FLAG_INTERACTIVE =
Used when converting AT service jobs into work items
0x1- TASK_FLAG_DELETE_WHEN_DONE =
The work item will be deleted when there are no more scheduled run times
0x2- TASK_FLAG_DISABLED =
The work item is disabled. Useful for temporarily disabling a task
0x4- TASK_FLAG_START_ONLY_IF_IDLE =
The work item begins only if the computer is not in use at the scheduled start time
0x10- TASK_FLAG_KILL_ON_IDLE_END =
The work item terminates if the computer makes an idle to non-idle transition while the work item is running
0x20- TASK_FLAG_DONT_START_IF_ON_BATTERIES =
The work item does not start if the computer is running on battery power
0x40- TASK_FLAG_KILL_IF_GOING_ON_BATTERIES =
The work item ends, and the associated application quits, if the computer switches to battery power
0x80- TASK_FLAG_RUN_ONLY_IF_DOCKED =
The work item starts only if the computer is in a docking station
0x100- TASK_FLAG_HIDDEN =
The work item created will be hidden
0x200- TASK_FLAG_RUN_IF_CONNECTED_TO_INTERNET =
The work item runs only if there is a valid internet connection
0x400- TASK_FLAG_RESTART_ON_IDLE_RESUME =
The work item starts again if the computer makes a non-idle to idle transition
0x800- TASK_FLAG_SYSTEM_REQUIRED =
The work item causes the system to be resumed, or awakened, if the system is running on batter power
0x1000- TASK_FLAG_RUN_ONLY_IF_LOGGED_ON =
The work item runs only if a specified account is logged on interactively
0x2000- TASK_TRIGGER_FLAG_HAS_END_DATE =
The task will stop at some point in time
0x1- TASK_TRIGGER_FLAG_KILL_AT_DURATION_END =
The task can be stopped at the end of the repetition period
0x2- TASK_TRIGGER_FLAG_DISABLED =
The task trigger is disabled
0x4- TASK_MAX_RUN_TIMES =
:stopdoc:
1440- TASKS_TO_RETRIEVE =
5- TASK_VALIDATE_ONLY =
Task creation
0x1- TASK_CREATE =
0x2- TASK_UPDATE =
0x4- TASK_CREATE_OR_UPDATE =
0x6- TASK_DISABLE =
0x8- TASK_DONT_ADD_PRINCIPAL_ACE =
0x10- TASK_IGNORE_REGISTRATION_TRIGGERS =
0x20- TASK_LOGON_NONE =
Task logon types
0- TASK_LOGON_PASSWORD =
1- TASK_LOGON_S4U =
2- TASK_LOGON_INTERACTIVE_TOKEN =
3- TASK_LOGON_GROUP =
4- TASK_LOGON_SERVICE_ACCOUNT =
5- TASK_LOGON_INTERACTIVE_TOKEN_OR_PASSWORD =
6- REALTIME_PRIORITY_CLASS =
Priority classes
0- HIGH_PRIORITY_CLASS =
1- ABOVE_NORMAL_PRIORITY_CLASS =
Or 3
2- NORMAL_PRIORITY_CLASS =
Or 5, 6
4- BELOW_NORMAL_PRIORITY_CLASS =
Or 8
7- IDLE_PRIORITY_CLASS =
Or 10
9- CLSCTX_INPROC_SERVER =
0x1- CLSID_CTask =
[0x148BD520,0xA2AB,0x11CE,0xB1,0x1F,0x00,0xAA,0x00,0x53,0x05,0x03].pack('LSSC8')
- CLSID_CTaskScheduler =
[0x148BD52A,0xA2AB,0x11CE,0xB1,0x1F,0x00,0xAA,0x00,0x53,0x05,0x03].pack('LSSC8')
- IID_ITaskScheduler =
[0x148BD527,0xA2AB,0x11CE,0xB1,0x1F,0x00,0xAA,0x00,0x53,0x05,0x03].pack('LSSC8')
- IID_ITask =
[0x148BD524,0xA2AB,0x11CE,0xB1,0x1F,0x00,0xAA,0x00,0x53,0x05,0x03].pack('LSSC8')
- IID_IPersistFile =
[0x0000010b,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46].pack('LSSC8')
- IDLE =
Shorthand constants
IDLE_PRIORITY_CLASS- NORMAL =
NORMAL_PRIORITY_CLASS- HIGH =
HIGH_PRIORITY_CLASS- REALTIME =
REALTIME_PRIORITY_CLASS- BELOW_NORMAL =
BELOW_NORMAL_PRIORITY_CLASS- ABOVE_NORMAL =
ABOVE_NORMAL_PRIORITY_CLASS- ONCE =
TASK_TIME_TRIGGER_ONCE- DAILY =
TASK_TIME_TRIGGER_DAILY- WEEKLY =
TASK_TIME_TRIGGER_WEEKLY- MONTHLYDATE =
TASK_TIME_TRIGGER_MONTHLYDATE- MONTHLYDOW =
TASK_TIME_TRIGGER_MONTHLYDOW- ON_IDLE =
TASK_EVENT_TRIGGER_ON_IDLE- AT_SYSTEMSTART =
TASK_EVENT_TRIGGER_AT_SYSTEMSTART- AT_LOGON =
TASK_EVENT_TRIGGER_AT_LOGON- FIRST_WEEK =
TASK_FIRST_WEEK- SECOND_WEEK =
TASK_SECOND_WEEK- THIRD_WEEK =
TASK_THIRD_WEEK- FOURTH_WEEK =
TASK_FOURTH_WEEK- LAST_WEEK =
TASK_LAST_WEEK- SUNDAY =
TASK_SUNDAY- MONDAY =
TASK_MONDAY- TUESDAY =
TASK_TUESDAY- WEDNESDAY =
TASK_WEDNESDAY- THURSDAY =
TASK_THURSDAY- FRIDAY =
TASK_FRIDAY- SATURDAY =
TASK_SATURDAY- JANUARY =
TASK_JANUARY- FEBRUARY =
TASK_FEBRUARY- MARCH =
TASK_MARCH- APRIL =
TASK_APRIL- MAY =
TASK_MAY- JUNE =
TASK_JUNE- JULY =
TASK_JULY- AUGUST =
TASK_AUGUST- SEPTEMBER =
TASK_SEPTEMBER- OCTOBER =
TASK_OCTOBER- NOVEMBER =
TASK_NOVEMBER- DECEMBER =
TASK_DECEMBER- INTERACTIVE =
TASK_FLAG_INTERACTIVE- DELETE_WHEN_DONE =
TASK_FLAG_DELETE_WHEN_DONE- DISABLED =
TASK_FLAG_DISABLED- START_ONLY_IF_IDLE =
TASK_FLAG_START_ONLY_IF_IDLE- KILL_ON_IDLE_END =
TASK_FLAG_KILL_ON_IDLE_END- DONT_START_IF_ON_BATTERIES =
TASK_FLAG_DONT_START_IF_ON_BATTERIES- KILL_IF_GOING_ON_BATTERIES =
TASK_FLAG_KILL_IF_GOING_ON_BATTERIES- RUN_ONLY_IF_DOCKED =
TASK_FLAG_RUN_ONLY_IF_DOCKED- HIDDEN =
TASK_FLAG_HIDDEN- RUN_IF_CONNECTED_TO_INTERNET =
TASK_FLAG_RUN_IF_CONNECTED_TO_INTERNET- RESTART_ON_IDLE_RESUME =
TASK_FLAG_RESTART_ON_IDLE_RESUME- SYSTEM_REQUIRED =
TASK_FLAG_SYSTEM_REQUIRED- RUN_ONLY_IF_LOGGED_ON =
TASK_FLAG_RUN_ONLY_IF_LOGGED_ON- FLAG_HAS_END_DATE =
TASK_TRIGGER_FLAG_HAS_END_DATE- FLAG_KILL_AT_DURATION_END =
TASK_TRIGGER_FLAG_KILL_AT_DURATION_END- FLAG_DISABLED =
TASK_TRIGGER_FLAG_DISABLED- MAX_RUN_TIMES =
TASK_MAX_RUN_TIMES
Constants included from Windows::TaskSchedulerHelper
Windows::TaskSchedulerHelper::FORMAT_MESSAGE_FROM_SYSTEM, Windows::TaskSchedulerHelper::FORMAT_MESSAGE_IGNORE_INSERTS, Windows::TaskSchedulerHelper::FORMAT_MESSAGE_MAX_WIDTH_MASK
Instance Attribute Summary collapse
-
#host ⇒ Object
(also: #machine)
readonly
Returns the value of attribute host.
-
#password ⇒ Object
:startdoc:.
Instance Method Summary collapse
-
#account_information ⇒ Object
Returns the user associated with the task or nil if no user has yet been associated with the task.
-
#activate(task) ⇒ Object
Activate the specified task.
-
#add_trigger(index, trigger) ⇒ Object
Adds a trigger at the specified index.
-
#application_name ⇒ Object
Returns the name of the application associated with the task.
-
#application_name=(app) ⇒ Object
Sets the name of the application associated with the task.
-
#comment ⇒ Object
(also: #description)
Returns the comment associated with the task, if any.
-
#comment=(comment) ⇒ Object
(also: #description=)
Sets the comment for the task.
-
#configure_registration_info(hash) ⇒ Object
Set registration information options.
-
#configure_settings(hash) ⇒ Object
Accepts a hash that lets you configure various task definition settings.
-
#creator ⇒ Object
(also: #author)
Returns the name of the user who created the task.
-
#creator=(creator) ⇒ Object
(also: #author=)
Sets the creator for the task.
-
#delete(task) ⇒ Object
Delete the specified task name.
-
#delete_trigger(index) ⇒ Object
Deletes the trigger at the specified index.
-
#enum ⇒ Object
(also: #tasks)
Returns an array of scheduled task names.
-
#exists?(task) ⇒ Boolean
Returns whether or not the specified task exists.
-
#exit_code ⇒ Object
Returns the exit code from the last scheduled run.
-
#initialize(task = nil, trigger = nil, folder = "\\", force = false) ⇒ TaskScheduler
constructor
Returns a new TaskScheduler object, attached to
folder. -
#machine=(host) ⇒ Object
(also: #host=)
Set the host on which the various TaskScheduler methods will execute.
-
#max_run_time ⇒ Object
Returns the maximum length of time, in milliseconds, that the task will run before terminating.
-
#max_run_time=(max_run_time) ⇒ Object
Sets the maximum length of time, in milliseconds, that the task can run before terminating.
-
#most_recent_run_time ⇒ Object
Returns a Time object indicating the most recent time the task ran or nil if the task has never run.
-
#new_work_item(task, trigger) ⇒ Object
(also: #new_task)
Creates a new work item (scheduled job) with the given
trigger. -
#next_run_time ⇒ Object
Returns a Time object that indicates the next time the task will run.
-
#parameters ⇒ Object
Returns the command line parameters for the task.
-
#parameters=(param) ⇒ Object
Sets the parameters for the task.
-
#priority ⇒ Object
Returns the task’s priority level.
-
#priority=(priority) ⇒ Object
Sets the priority of the task.
-
#run ⇒ Object
Execute the current task.
-
#save(file = nil) ⇒ Object
This method no longer has any effect.
-
#set_account_information(user, password) ⇒ Object
Sets the
userandpasswordfor the given task. -
#set_machine(host, user = nil, domain = nil, password = nil) ⇒ Object
(also: #set_host)
Similar to the TaskScheduler#machine= method, this method also allows you to pass a user, domain and password as needed.
-
#status ⇒ Object
Returns the status of the currently active task.
-
#terminate ⇒ Object
(also: #stop)
Terminate (stop) the current task.
-
#trigger(index) ⇒ Object
Returns a hash that describes the trigger at the given index for the current task.
-
#trigger=(trigger) ⇒ Object
Sets the trigger for the currently active task.
-
#trigger_count ⇒ Object
Returns the number of triggers associated with the active task.
-
#trigger_string(index) ⇒ Object
Returns a string that describes the current trigger at the specified index for the active task.
-
#working_directory ⇒ Object
Returns the working directory for the task.
-
#working_directory=(dir) ⇒ Object
Sets the working directory for the task.
Methods included from Windows::TaskSchedulerHelper
Constructor Details
#initialize(task = nil, trigger = nil, folder = "\\", force = false) ⇒ TaskScheduler
Returns a new TaskScheduler object, attached to folder. If that folder does not exist, but the force option is set to true, then it will be created. Otherwise an error will be raised. The default is to use the root folder.
If task and trigger are present, then a new task is generated as well. This is effectively the same as .new + #new_work_item.
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/win32/taskscheduler.rb', line 236 def initialize(task = nil, trigger = nil, folder = "\\", force = false) @folder = folder @force = force @host = Socket.gethostname @task = nil @password = nil raise ArgumentError, "invalid folder" unless folder.include?("\\") unless [TrueClass, FalseClass].include?(force.class) raise TypeError, "invalid force value" end begin @service = WIN32OLE.new('Schedule.Service') rescue WIN32OLERuntimeError => err raise Error, err.inspect end @service.Connect if folder != "\\" begin @root = @service.GetFolder(folder) rescue WIN32OLERuntimeError => err if force @root.CreateFolder(folder) @root = @service.GetFolder(folder) else raise ArgumentError, "folder '#{folder}' not found" end end else @root = @service.GetFolder(folder) end if task && trigger new_work_item(task, trigger) end end |
Instance Attribute Details
#host ⇒ Object (readonly) Also known as: machine
Returns the value of attribute host.
226 227 228 |
# File 'lib/win32/taskscheduler.rb', line 226 def host @host end |
#password ⇒ Object
:startdoc:
225 226 227 |
# File 'lib/win32/taskscheduler.rb', line 225 def password @password end |
Instance Method Details
#account_information ⇒ Object
Returns the user associated with the task or nil if no user has yet been associated with the task.
418 419 420 |
# File 'lib/win32/taskscheduler.rb', line 418 def account_information @task.nil? ? nil : @task.Definition.Principal.UserId end |
#activate(task) ⇒ Object
Activate the specified task.
303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/win32/taskscheduler.rb', line 303 def activate(task) raise TypeError unless task.is_a?(String) begin registeredTask = @root.GetTask(task) registeredTask.Enabled = 1 @task = registeredTask rescue WIN32OLERuntimeError => err raise Error, ole_error('activate', err) end end |
#add_trigger(index, trigger) ⇒ Object
Adds a trigger at the specified index.
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 |
# File 'lib/win32/taskscheduler.rb', line 935 def add_trigger(index, trigger) raise TypeError unless index.is_a?(Numeric) raise TypeError unless trigger.is_a?(Hash) check_for_active_task definition = @task.Definition case trigger[:trigger_type] when TASK_TIME_TRIGGER_DAILY type = 2 when TASK_TIME_TRIGGER_WEEKLY type = 3 when TASK_TIME_TRIGGER_MONTHLYDATE type = 4 when TASK_TIME_TRIGGER_MONTHLYDOW type = 5 when TASK_TIME_TRIGGER_ONCE type = 1 else raise Error, 'Unknown trigger type' end startTime = "%04d-%02d-%02dT%02d:%02d:00" % [ trigger[:start_year], trigger[:start_month], trigger[:start_day], trigger[:start_hour], trigger[:start_minute] ] # Set defaults trigger[:end_year] ||= 0 trigger[:end_month] ||= 0 trigger[:end_day] ||= 0 endTime = "%04d-%02d-%02dT00:00:00" % [ trigger[:end_year], trigger[:end_month], trigger[:end_day] ] trig = definition.Triggers.Create(type) trig.Id = "RegistrationTriggerId#{definition.Triggers.Count}" trig.StartBoundary = startTime trig.EndBoundary = endTime if endTime != '0000-00-00T00:00:00' trig.Enabled = true repetitionPattern = trig.Repetition if trigger[:minutes_duration].to_i > 0 repetitionPattern.Duration = "PT#{trigger[:minutes_duration]||0}M" end if trigger[:minutes_interval].to_i > 0 repetitionPattern.Interval = "PT#{trigger[:minutes_interval]||0}M" end tmp = trigger[:type] tmp = nil unless tmp.is_a?(Hash) case trigger[:trigger_type] when TASK_TIME_TRIGGER_DAILY trig.DaysInterval = tmp[:days_interval] if tmp && tmp[:days_interval] if trigger[:random_minutes_interval].to_i > 0 trig.RandomDelay = "PT#{trigger[:random_minutes_interval]}M" end when TASK_TIME_TRIGGER_WEEKLY trig.DaysOfWeek = tmp[:days_of_week] if tmp && tmp[:days_of_week] trig.WeeksInterval = tmp[:weeks_interval] if tmp && tmp[:weeks_interval] if trigger[:random_minutes_interval].to_i > 0 trig.RandomDelay = "PT#{trigger[:random_minutes_interval]||0}M" end when TASK_TIME_TRIGGER_MONTHLYDATE trig.MonthsOfYear = tmp[:months] if tmp && tmp[:months] trig.DaysOfMonth = tmp[:days] if tmp && tmp[:days] if trigger[:random_minutes_interval].to_i > 0 trig.RandomDelay = "PT#{trigger[:random_minutes_interval]||0}M" end when TASK_TIME_TRIGGER_MONTHLYDOW trig.MonthsOfYear = tmp[:months] if tmp && tmp[:months] trig.DaysOfWeek = tmp[:days_of_week] if tmp && tmp[:days_of_week] trig.WeeksOfMonth = tmp[:weeks] if tmp && tmp[:weeks] if trigger[:random_minutes_interval].to_i > 0 trig.RandomDelay = "PT#{trigger[:random_minutes_interval]||0}M" end when TASK_TIME_TRIGGER_ONCE if trigger[:random_minutes_interval].to_i > 0 trig.RandomDelay = "PT#{trigger[:random_minutes_interval]||0}M" end end update_task_definition(definition) true end |
#application_name ⇒ Object
Returns the name of the application associated with the task. If no application is associated with the task then nil is returned.
425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/win32/taskscheduler.rb', line 425 def application_name check_for_active_task app = nil @task.Definition.Actions.each do |action| if action.Type == 0 # TASK_ACTION_EXEC app = action.Path break end end app end |
#application_name=(app) ⇒ Object
Sets the name of the application associated with the task.
442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'lib/win32/taskscheduler.rb', line 442 def application_name=(app) raise TypeError unless app.is_a?(String) check_for_active_task definition = @task.Definition definition.Actions.each do |action| action.Path = app if action.Type == 0 end update_task_definition(definition) app end |
#comment ⇒ Object Also known as: description
Returns the comment associated with the task, if any.
1054 1055 1056 1057 |
# File 'lib/win32/taskscheduler.rb', line 1054 def comment check_for_active_task @task.Definition.RegistrationInfo.Description end |
#comment=(comment) ⇒ Object Also known as: description=
Sets the comment for the task.
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 |
# File 'lib/win32/taskscheduler.rb', line 1063 def comment=(comment) raise TypeError unless comment.is_a?(String) check_for_active_task definition = @task.Definition definition.RegistrationInfo.Description = comment update_task_definition(definition) comment end |
#configure_registration_info(hash) ⇒ Object
Set registration information options. The possible options are:
-
author
-
date
-
description (or comment)
-
documentation
-
security_descriptor (should be a Win32::Security::SID)
-
source
-
uri
-
version
-
xml_text (or xml)
Note that most of these options have standalone methods as well, e.g. calling ts.configure_registration_info(:author => ‘Dan’) is the same as calling ts.author = ‘Dan’.
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 |
# File 'lib/win32/taskscheduler.rb', line 1261 def configure_registration_info(hash) raise TypeError unless hash.is_a?(Hash) check_for_active_task definition = @task.Definition = hash[:author] date = hash[:date] description = hash[:description] || hash[:comment] documentation = hash[:documentation] security_descriptor = hash[:security_descriptor] source = hash[:source] uri = hash[:uri] version = hash[:version] xml_text = hash[:xml_text] || hash[:xml] definition.RegistrationInfo.Author = if definition.RegistrationInfo.Date = date if date definition.RegistrationInfo.Description = description if description definition.RegistrationInfo.Documentation = documentation if documentation definition.RegistrationInfo.SecurityDescriptor = security_descriptor if security_descriptor definition.RegistrationInfo.Source = source if source definition.RegistrationInfo.URI = uri if uri definition.RegistrationInfo.Version = version if version definition.RegistrationInfo.XmlText = xml_text if xml_text update_task_definition(definition) hash end |
#configure_settings(hash) ⇒ Object
Accepts a hash that lets you configure various task definition settings. The possible options are:
-
allow_demand_start
-
allow_hard_terminate
-
compatibility
-
delete_expired_task_after
-
disallowed_start_if_on_batteries
-
enabled
-
execution_time_limit (or max_run_time)
-
hidden
-
idle_settings
-
network_settings
-
priority
-
restart_count
-
restart_interval
-
run_only_if_idle
-
run_only_if_network_available
-
start_when_available
-
stop_if_going_on_batteries
-
wake_to_run
-
xml_text (or xml)
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 |
# File 'lib/win32/taskscheduler.rb', line 1194 def configure_settings(hash) raise TypeError unless hash.is_a?(Hash) check_for_active_task definition = @task.Definition allow_demand_start = hash[:allow_demand_start] allow_hard_terminate = hash[:allow_hard_terminate] compatibility = hash[:compatibility] delete_expired_task_after = hash[:delete_expired_task_after] disallow_start_if_on_batteries = hash[:disallow_start_if_on_batteries] enabled = hash[:enabled] execution_time_limit = hash[:execution_time_limit] || hash[:max_run_time] hidden = hash[:hidden] idle_settings = hash[:idle_settings] network_settings = hash[:network_settings] priority = hash[:priority] restart_count = hash[:restart_count] restart_interval = hash[:restart_interval] run_only_if_idle = hash[:run_only_if_idle] run_only_if_network_available = hash[:run_only_if_network_available] start_when_available = hash[:start_when_available] stop_if_going_on_batteries = hash[:stop_if_going_on_batteries] wake_to_run = hash[:wake_to_run] xml_text = hash[:xml_text] || hash[:xml] definition.Settings.AllowDemandStart = allow_demand_start if allow_demand_start definition.Settings.AllowHardTerminate = allow_hard_terminate if allow_hard_terminate definition.Settings.Compatibility = compatibility if compatibility definition.Settings.DeleteExpiredTaskAfter = delete_expired_task_after if delete_expired_task_after definition.Settings.DisallowStartIfOnBatteries = disallow_start_if_on_batteries if disallow_start_if_on_batteries definition.Settings.Enabled = enabled if enabled definition.Settings.ExecutionTimeLimit = execution_time_limit if execution_time_limit definition.Settings.Hidden = hidden if hidden definition.Settings.IdleSettings = idle_settings if idle_settings definition.Settings.NetworkSettings = network_settings if network_settings definition.Settings.Priority = priority if priority definition.Settings.RestartCount = restart_count if restart_count definition.Settings.RestartInterval = restart_interval if restart_interval definition.Settings.RunOnlyIfIdle = run_only_if_idle if run_only_if_idle definition.Settings.RunOnlyIfNetworkAvailable = run_only_if_network_available if run_only_if_network_available definition.Settings.StartWhenAvailable = start_when_available if start_when_available definition.Settings.StopIfGoingOnBatteries = stop_if_going_on_batteries if stop_if_going_on_batteries definition.Settings.WakeToRun = wake_to_run if wake_to_run definition.Settings.XmlText = xml_text if xml_text update_task_definition(definition) hash end |
#creator ⇒ Object Also known as:
Returns the name of the user who created the task.
1078 1079 1080 1081 |
# File 'lib/win32/taskscheduler.rb', line 1078 def creator check_for_active_task @task.Definition.RegistrationInfo.Author end |
#creator=(creator) ⇒ Object Also known as:
Sets the creator for the task.
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 |
# File 'lib/win32/taskscheduler.rb', line 1087 def creator=(creator) raise TypeError unless creator.is_a?(String) check_for_active_task definition = @task.Definition definition.RegistrationInfo.Author = creator update_task_definition(definition) creator end |
#delete(task) ⇒ Object
Delete the specified task name.
317 318 319 320 321 322 323 324 325 |
# File 'lib/win32/taskscheduler.rb', line 317 def delete(task) raise TypeError unless task.is_a?(String) begin @root.DeleteTask(task, 0) rescue WIN32OLERuntimeError => err raise Error, ole_error('DeleteTask', err) end end |
#delete_trigger(index) ⇒ Object
Deletes the trigger at the specified index. – TODO: Fix.
732 733 734 735 736 737 738 739 740 741 742 |
# File 'lib/win32/taskscheduler.rb', line 732 def delete_trigger(index) raise TypeError unless index.is_a?(Numeric) check_for_active_task index += 1 # first item index is 1 definition = @task.Definition definition.Triggers.Remove(index) update_task_definition(definition) index end |
#enum ⇒ Object Also known as: tasks
Returns an array of scheduled task names.
280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/win32/taskscheduler.rb', line 280 def enum # Get the task folder that contains the tasks. taskCollection = @root.GetTasks(0) array = [] taskCollection.each do |registeredTask| array << registeredTask.Name end array end |
#exists?(task) ⇒ Boolean
Returns whether or not the specified task exists.
297 298 299 |
# File 'lib/win32/taskscheduler.rb', line 297 def exists?(task) enum.include?(task) end |
#exit_code ⇒ Object
Returns the exit code from the last scheduled run.
1047 1048 1049 1050 |
# File 'lib/win32/taskscheduler.rb', line 1047 def exit_code check_for_active_task @task.LastTaskResult end |
#machine=(host) ⇒ Object Also known as: host=
Set the host on which the various TaskScheduler methods will execute. This method may require administrative privileges.
355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/win32/taskscheduler.rb', line 355 def machine=(host) raise TypeError unless host.is_a?(String) begin @service.Connect(host) rescue WIN32OLERuntimeError => err raise Error, ole_error('Connect', err) end @host = host host end |
#max_run_time ⇒ Object
Returns the maximum length of time, in milliseconds, that the task will run before terminating.
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 |
# File 'lib/win32/taskscheduler.rb', line 1127 def max_run_time check_for_active_task t = @task.Definition.Settings.ExecutionTimeLimit year = t.scan(/(\d+?)Y/).flatten.first month = t.scan(/(\d+?)M/).flatten.first day = t.scan(/(\d+?)D/).flatten.first hour = t.scan(/(\d+?)H/).flatten.first min = t.scan(/T.*(\d+?)M/).flatten.first sec = t.scan(/(\d+?)S/).flatten.first time = 0 time += year.to_i * 365 if year time += month.to_i * 30 if month time += day.to_i if day time *= 24 time += hour.to_i if hour time *= 60 time += min.to_i if min time *= 60 time += sec.to_i if sec time *= 1000 time end |
#max_run_time=(max_run_time) ⇒ Object
Sets the maximum length of time, in milliseconds, that the task can run before terminating. Returns the value you specified if successful.
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 |
# File 'lib/win32/taskscheduler.rb', line 1156 def max_run_time=(max_run_time) raise TypeError unless max_run_time.is_a?(Numeric) check_for_active_task t = max_run_time t /= 1000 limit ="PT#{t}S" definition = @task.Definition definition.Settings.ExecutionTimeLimit = limit update_task_definition(definition) max_run_time end |
#most_recent_run_time ⇒ Object
Returns a Time object indicating the most recent time the task ran or nil if the task has never run.
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 |
# File 'lib/win32/taskscheduler.rb', line 1110 def most_recent_run_time check_for_active_task time = nil begin time = Time.parse(@task.LastRunTime) rescue # Ignore end time end |
#new_work_item(task, trigger) ⇒ Object Also known as: new_task
Creates a new work item (scheduled job) with the given trigger. The trigger variable is a hash of options that define when the scheduled job should run.
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 |
# File 'lib/win32/taskscheduler.rb', line 581 def new_work_item(task, trigger) raise TypeError unless task.is_a?(String) raise TypeError unless trigger.is_a?(Hash) validate_trigger(trigger) taskDefinition = @service.NewTask(0) taskDefinition.RegistrationInfo.Description = '' taskDefinition.RegistrationInfo.Author = '' taskDefinition.Settings.StartWhenAvailable = true taskDefinition.Settings.Enabled = true taskDefinition.Settings.Hidden = false case trigger[:trigger_type] when TASK_TIME_TRIGGER_ONCE type = 1 when TASK_TIME_TRIGGER_DAILY type = 2 when TASK_TIME_TRIGGER_WEEKLY type = 3 when TASK_TIME_TRIGGER_MONTHLYDATE type = 4 when TASK_TIME_TRIGGER_MONTHLYDOW type = 5 when TASK_EVENT_TRIGGER_ON_IDLE type = 6 when TASK_EVENT_TRIGGER_AT_SYSTEMSTART type = 8 when TASK_EVENT_TRIGGER_AT_LOGON type = 9 else raise ArgumentError, 'Unknown trigger type' end startTime = "%04d-%02d-%02dT%02d:%02d:00" % [ trigger[:start_year], trigger[:start_month], trigger[:start_day], trigger[:start_hour], trigger[:start_minute] ] # Set defaults trigger[:end_year] ||= 0 trigger[:end_month] ||= 0 trigger[:end_day] ||= 0 endTime = "%04d-%02d-%02dT00:00:00" % [ trigger[:end_year], trigger[:end_month], trigger[:end_day] ] trig = taskDefinition.Triggers.Create(type) trig.Id = "RegistrationTriggerId#{taskDefinition.Triggers.Count}" trig.StartBoundary = startTime trig.EndBoundary = endTime if endTime != '0000-00-00T00:00:00' trig.Enabled = true repetitionPattern = trig.Repetition if trigger[:minutes_duration].to_i > 0 repetitionPattern.Duration = "PT#{trigger[:minutes_duration]||0}M" end if trigger[:minutes_interval].to_i > 0 repetitionPattern.Interval = "PT#{trigger[:minutes_interval]||0}M" end tmp = trigger[:type] tmp = nil unless tmp.is_a?(Hash) case trigger[:trigger_type] when TASK_TIME_TRIGGER_DAILY trig.DaysInterval = tmp[:days_interval] if tmp && tmp[:days_interval] if trigger[:random_minutes_interval].to_i > 0 trig.RandomDelay = "PT#{trigger[:random_minutes_interval]}M" end when TASK_TIME_TRIGGER_WEEKLY trig.DaysOfWeek = tmp[:days_of_week] if tmp && tmp[:days_of_week] trig.WeeksInterval = tmp[:weeks_interval] if tmp && tmp[:weeks_interval] if trigger[:random_minutes_interval].to_i > 0 trig.RandomDelay = "PT#{trigger[:random_minutes_interval]||0}M" end when TASK_TIME_TRIGGER_MONTHLYDATE trig.MonthsOfYear = tmp[:months] if tmp && tmp[:months] trig.DaysOfMonth = tmp[:days] if tmp && tmp[:days] if trigger[:random_minutes_interval].to_i > 0 trig.RandomDelay = "PT#{trigger[:random_minutes_interval]||0}M" end when TASK_TIME_TRIGGER_MONTHLYDOW trig.MonthsOfYear = tmp[:months] if tmp && tmp[:months] trig.DaysOfWeek = tmp[:days_of_week] if tmp && tmp[:days_of_week] trig.WeeksOfMonth = tmp[:weeks] if tmp && tmp[:weeks] if trigger[:random_minutes_interval].to_i>0 trig.RandomDelay = "PT#{trigger[:random_minutes_interval]||0}M" end when TASK_TIME_TRIGGER_ONCE if trigger[:random_minutes_interval].to_i > 0 trig.RandomDelay = "PT#{trigger[:random_minutes_interval]||0}M" end end act = taskDefinition.Actions.Create(0) act.Path = 'cmd' begin @task = @root.RegisterTaskDefinition( task, taskDefinition, TASK_CREATE_OR_UPDATE, nil, nil, TASK_LOGON_INTERACTIVE_TOKEN ) rescue WIN32OLERuntimeError => err raise Error, ole_error('RegisterTaskDefinition', err) end @task = @root.GetTask(task) end |
#next_run_time ⇒ Object
Returns a Time object that indicates the next time the task will run.
1102 1103 1104 1105 |
# File 'lib/win32/taskscheduler.rb', line 1102 def next_run_time check_for_active_task @task.NextRunTime end |
#parameters ⇒ Object
Returns the command line parameters for the task.
459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/win32/taskscheduler.rb', line 459 def parameters check_for_active_task param = nil @task.Definition.Actions.each do |action| param = action.Arguments if action.Type == 0 end param end |
#parameters=(param) ⇒ Object
Sets the parameters for the task. These parameters are passed as command line arguments to the application the task will run. To clear the command line parameters set it to an empty string. – NOTE: Again, it seems the task must be reactivated to be picked up.
477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
# File 'lib/win32/taskscheduler.rb', line 477 def parameters=(param) raise TypeError unless param.is_a?(String) check_for_active_task definition = @task.Definition definition.Actions.each do |action| action.Arguments = param if action.Type == 0 end update_task_definition(definition) param end |
#priority ⇒ Object
Returns the task’s priority level. Possible values are ‘idle’, ‘normal’, ‘high’, ‘realtime’, ‘below_normal’, ‘above_normal’, and ‘unknown’.
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 |
# File 'lib/win32/taskscheduler.rb', line 529 def priority check_for_active_task case @task.Definition.Settings.Priority when 0 priority = 'critical' when 1 priority = 'highest' when 2 priority = 'above_normal' when 3 priority = 'above_normal' when 4 priority = 'normal' when 5 priority = 'normal' when 6 priority = 'normal' when 7 priority = 'below_normal' when 8 priority = 'below_normal' when 9 priority = 'lowest' when 10 priority = 'idle' else priority = 'unknown' end priority end |
#priority=(priority) ⇒ Object
Sets the priority of the task. The priority should be a numeric priority constant value.
565 566 567 568 569 570 571 572 573 574 575 |
# File 'lib/win32/taskscheduler.rb', line 565 def priority=(priority) raise TypeError unless priority.is_a?(Numeric) check_for_active_task definition = @task.Definition definition.Settings.Priority = priority update_task_definition(definition) priority end |
#run ⇒ Object
Execute the current task.
329 330 331 332 |
# File 'lib/win32/taskscheduler.rb', line 329 def run check_for_active_task @task.run(nil) end |
#save(file = nil) ⇒ Object
This method no longer has any effect. It is a no-op that remains for backwards compatibility. It will be removed in 0.4.0.
337 338 339 340 341 |
# File 'lib/win32/taskscheduler.rb', line 337 def save(file = nil) warn DeprecatedMethodWarning, "this method is no longer necessary" check_for_active_task # Do nothing, deprecated. end |
#set_account_information(user, password) ⇒ Object
Sets the user and password for the given task. If the user and password are set properly then true is returned.
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/win32/taskscheduler.rb', line 392 def set_account_information(user, password) raise TypeError unless user.is_a?(String) raise TypeError unless password.is_a?(String) check_for_active_task @password = password begin @task = @root.RegisterTaskDefinition( @task.Path, @task.Definition, TASK_CREATE_OR_UPDATE, user, password, TASK_LOGON_PASSWORD ) rescue WIN32OLERuntimeError => err raise Error, ole_error('RegisterTaskDefinition', err) end true end |
#set_machine(host, user = nil, domain = nil, password = nil) ⇒ Object Also known as: set_host
Similar to the TaskScheduler#machine= method, this method also allows you to pass a user, domain and password as needed. This method may require administrative privileges.
372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/win32/taskscheduler.rb', line 372 def set_machine(host, user = nil, domain = nil, password = nil) raise TypeError unless host.is_a?(String) begin @service.Connect(host, user, domain, password) rescue WIN32OLERuntimeError => err raise Error, ole_error('Connect', err) end @host = host host end |
#status ⇒ Object
Returns the status of the currently active task. Possible values are ‘ready’, ‘running’, ‘not scheduled’ or ‘unknown’.
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 |
# File 'lib/win32/taskscheduler.rb', line 1028 def status check_for_active_task case @task.State when 3 status = 'ready' when 4 status = 'running' when 1 status = 'not scheduled' else status = 'unknown' end status end |
#terminate ⇒ Object Also known as: stop
Terminate (stop) the current task.
345 346 347 348 |
# File 'lib/win32/taskscheduler.rb', line 345 def terminate check_for_active_task @task.stop(nil) end |
#trigger(index) ⇒ Object
Returns a hash that describes the trigger at the given index for the current task.
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 |
# File 'lib/win32/taskscheduler.rb', line 747 def trigger(index) raise TypeError unless index.is_a?(Numeric) check_for_active_task index += 1 # first item index is 1 begin trig = @task.Definition.Triggers.Item(index) rescue WIN32OLERuntimeError => err raise Error, ole_error('Item', err) end trigger = {} trigger[:start_year], trigger[:start_month], trigger[:start_day], trigger[:start_hour], trigger[:start_minute] = trig.StartBoundary.scan(/(\d+)-(\d+)-(\d+)T(\d+):(\d+)/).first trigger[:end_year], trigger[:end_month], trigger[:end_day] = trig.StartBoundary.scan(/(\d+)-(\d+)-(\d+)T/).first if trig.Repetition.Duration != "" trigger[:minutes_duration] = trig.Repetition.Duration.scan(/(\d+)M/)[0][0].to_i end if trig.Repetition.Interval != "" trigger[:minutes_interval] = trig.Repetition.Interval.scan(/(\d+)M/)[0][0].to_i end if trig.RandomDelay != "" trigger[:random_minutes_interval] = trig.RandomDelay.scan(/(\d+)M/)[0][0].to_i end case trig.Type when 2 trigger[:trigger_type] = TASK_TIME_TRIGGER_DAILY tmp = {} tmp[:days_interval] = trig.DaysInterval trigger[:type] = tmp when 3 trigger[:trigger_type] = TASK_TIME_TRIGGER_WEEKLY tmp = {} tmp[:weeks_interval] = trig.WeeksInterval tmp[:days_of_week] = trig.DaysOfWeek trigger[:type] = tmp when 4 trigger[:trigger_type] = TASK_TIME_TRIGGER_MONTHLYDATE tmp = {} tmp[:months] = trig.MonthsOfYear tmp[:days] = trig.DaysOfMonth trigger[:type] = tmp when 5 trigger[:trigger_type] = TASK_TIME_TRIGGER_MONTHLYDOW tmp = {} tmp[:months] = trig.MonthsOfYear tmp[:days_of_week] = trig.DaysOfWeek tmp[:weeks] = trig.weeks trigger[:type] = tmp when 1 trigger[:trigger_type] = TASK_TIME_TRIGGER_ONCE tmp = {} tmp[:once] = nil trigger[:type] = tmp else raise Error, 'Unknown trigger type' end trigger end |
#trigger=(trigger) ⇒ Object
Sets the trigger for the currently active task. The trigger is a hash with the following possible options:
-
days
-
days_interval
-
days_of_week
-
end_day
-
end_month
-
end_year
-
flags
-
minutes_duration
-
minutes_interval
-
months
-
random_minutes_interval
-
start_day
-
start_hour
-
start_minute
-
start_month
-
start_year
-
trigger_type
-
type
-
weeks
-
weeks_interval
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 |
# File 'lib/win32/taskscheduler.rb', line 839 def trigger=(trigger) raise TypeError unless trigger.is_a?(Hash) check_for_active_task validate_trigger(trigger) definition = @task.Definition definition.Triggers.Clear() case trigger[:trigger_type] when TASK_TIME_TRIGGER_ONCE type = 1 when TASK_TIME_TRIGGER_DAILY type = 2 when TASK_TIME_TRIGGER_WEEKLY type = 3 when TASK_TIME_TRIGGER_MONTHLYDATE type = 4 when TASK_TIME_TRIGGER_MONTHLYDOW type = 5 when TASK_EVENT_TRIGGER_ON_IDLE type = 6 when TASK_EVENT_TRIGGER_AT_SYSTEM_START type = 8 when TASK_EVENT_TRIGGER_AT_LOGON type = 9 else raise Error, 'Unknown trigger type' end startTime = "%04d-%02d-%02dT%02d:%02d:00" % [ trigger[:start_year], trigger[:start_month], trigger[:start_day], trigger[:start_hour], trigger[:start_minute] ] endTime = "%04d-%02d-%02dT00:00:00" % [ trigger[:end_year], trigger[:end_month], trigger[:end_day] ] trig = definition.Triggers.Create(type) trig.Id = "RegistrationTriggerId#{definition.Triggers.Count}" trig.StartBoundary = startTime trig.EndBoundary = endTime if endTime != '0000-00-00T00:00:00' trig.Enabled = true repetitionPattern = trig.Repetition if trigger[:minutes_duration].to_i > 0 repetitionPattern.Duration = "PT#{trigger[:minutes_duration]||0}M" end if trigger[:minutes_interval].to_i > 0 repetitionPattern.Interval = "PT#{trigger[:minutes_interval]||0}M" end tmp = trigger[:type] tmp = nil unless tmp.is_a?(Hash) case trigger[:trigger_type] when TASK_TIME_TRIGGER_DAILY trig.DaysInterval = tmp[:days_interval] if tmp && tmp[:days_interval] if trigger[:random_minutes_interval].to_i > 0 trig.RandomDelay = "PT#{trigger[:random_minutes_interval]}M" end when TASK_TIME_TRIGGER_WEEKLY trig.DaysOfWeek = tmp[:days_of_week] if tmp && tmp[:days_of_week] trig.WeeksInterval = tmp[:weeks_interval] if tmp && tmp[:weeks_interval] if trigger[:random_minutes_interval].to_i > 0 trig.RandomDelay = "PT#{trigger[:random_minutes_interval]||0}M" end when TASK_TIME_TRIGGER_MONTHLYDATE trig.MonthsOfYear = tmp[:months] if tmp && tmp[:months] trig.DaysOfMonth = tmp[:days] if tmp && tmp[:days] if trigger[:random_minutes_interval].to_i > 0 trig.RandomDelay = "PT#{trigger[:random_minutes_interval]||0}M" end when TASK_TIME_TRIGGER_MONTHLYDOW trig.MonthsOfYear = tmp[:months] if tmp && tmp[:months] trig.DaysOfWeek = tmp[:days_of_week] if tmp && tmp[:days_of_week] trig.WeeksOfMonth = tmp[:weeks] if tmp && tmp[:weeks] if trigger[:random_minutes_interval].to_i > 0 trig.RandomDelay = "PT#{trigger[:random_minutes_interval]||0}M" end when TASK_TIME_TRIGGER_ONCE if trigger[:random_minutes_interval].to_i > 0 trig.RandomDelay = "PT#{trigger[:random_minutes_interval]||0}M" end end update_task_definition(definition) trigger end |
#trigger_count ⇒ Object
Returns the number of triggers associated with the active task.
703 704 705 706 707 |
# File 'lib/win32/taskscheduler.rb', line 703 def trigger_count raise Error, "No currently active task" if @task.nil? @task.Definition.Triggers.Count end |
#trigger_string(index) ⇒ Object
Returns a string that describes the current trigger at the specified index for the active task.
Example: “At 7:14 AM every day, starting 4/11/2015”
714 715 716 717 718 719 720 721 722 723 724 725 726 |
# File 'lib/win32/taskscheduler.rb', line 714 def trigger_string(index) raise TypeError unless index.is_a?(Numeric) check_for_active_task index += 1 # first item index is 1 begin trigger = @task.Definition.Triggers.Item(index) rescue WIN32OLERuntimeError raise Error, "No trigger found at index '#{index}'" end "Starting #{trigger.StartBoundary}" end |
#working_directory ⇒ Object
Returns the working directory for the task.
494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/win32/taskscheduler.rb', line 494 def working_directory check_for_active_task dir = nil @task.Definition.Actions.each do |action| dir = action.WorkingDirectory if action.Type == 0 end dir end |
#working_directory=(dir) ⇒ Object
Sets the working directory for the task. – TODO: Why do I have to reactivate the task to see the change?
510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
# File 'lib/win32/taskscheduler.rb', line 510 def working_directory=(dir) raise TypeError unless dir.is_a?(String) check_for_active_task definition = @task.Definition definition.Actions.each do |action| action.WorkingDirectory = dir if action.Type == 0 end update_task_definition(definition) dir end |