lib/win32/taskscheduler.rb in win32-taskscheduler-2.0.0 vs lib/win32/taskscheduler.rb in win32-taskscheduler-2.0.1
- old
+ new
@@ -510,11 +510,11 @@
# 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.
#
- def new_work_item(task, trigger, userinfo = { user: nil, password: nil })
+ def new_work_item(task, trigger, userinfo = { user: nil, password: nil, interactive: false })
raise TypeError unless userinfo.is_a?(Hash) && task.is_a?(String) && trigger.is_a?(Hash)
# If user ID is not given, consider it as a 'SYSTEM' user
userinfo[:user] = SERVICE_ACCOUNT_USERS.first if userinfo[:user].to_s.empty?
@@ -607,10 +607,11 @@
act = taskDefinition.Actions.Create(0)
act.Path = 'cmd'
@password = userinfo[:password]
+ @interactive = userinfo[:interactive]
register_task_definition(taskDefinition, task, userinfo[:user], userinfo[:password])
@task = @root.GetTask(task)
end
@@ -1234,10 +1235,11 @@
definition.Principal.DisplayName = principals[:display_name] if principals[:display_name].to_s != ""
definition.Principal.UserId = principals[:user_id] if principals[:user_id].to_s != ""
definition.Principal.LogonType = principals[:logon_type] if principals[:logon_type].to_s != ""
definition.Principal.GroupId = principals[:group_id] if principals[:group_id].to_s != ""
definition.Principal.RunLevel = principals[:run_level] if principals[:run_level].to_s != ""
+ @interactive = true if principals[:logon_type] == TASK_LOGON_INTERACTIVE_TOKEN
register_task_definition(definition)
principals
end
# Returns a hash containing all the principal information of the current task
@@ -1415,12 +1417,16 @@
def logon_type(user_id, password)
if service_account_user?(user_id)
TASK_LOGON_SERVICE_ACCOUNT
elsif group_user?(user_id)
TASK_LOGON_GROUP
- elsif !password.to_s.empty? # Password is present
- TASK_LOGON_PASSWORD
+ elsif !user_id.to_s.empty? && !password.to_s.empty?
+ if @interactive
+ TASK_LOGON_INTERACTIVE_TOKEN
+ else
+ TASK_LOGON_PASSWORD
+ end
else
TASK_LOGON_INTERACTIVE_TOKEN
end
end
@@ -1433,9 +1439,10 @@
#
# @return [Integer] Logon Types
#
def register_task_definition(definition, path = nil, user_id = nil, password = nil)
user_id ||= task_user_id(definition)
+ password ||= @password
path ||= @task.Path
@task = @root.RegisterTaskDefinition(
path, # Path (name) of the task
definition, # definition of the task
TASK_CREATE_OR_UPDATE, # Equivalent to TASK_CREATE | TASK_UPDATE