schtasks: Task Scheduling

TaskSchedulerR Documentation

Task Scheduling

Description

An R6 class for creating and checking a task call and wrappers

Usage

schtasks_run(
  task_name,
  system = NULL,
  username = NULL,
  password = NULL,
  quiet = FALSE
)

schtasks_end(
  task_name,
  system = NULL,
  username = NULL,
  password = NULL,
  quiet = FALSE
)

schtasks_create(
  task_name,
  system = NULL,
  username = NULL,
  password = NULL,
  runas_username = NULL,
  runas_password = NULL,
  schedule = NULL,
  modifier = NULL,
  days = NULL,
  months = NULL,
  idle_time = NULL,
  task_run = NULL,
  start_time = NULL,
  interval = NULL,
  end_time = NULL,
  duration = NULL,
  terminate = FALSE,
  start_date = NULL,
  end_date = NULL,
  channel_name = NULL,
  delete_after_final = FALSE,
  v1 = FALSE,
  force = FALSE,
  level = c("limited", "highest"),
  delay_time = NULL,
  quiet = FALSE
)

schtasks_create_xml(xml_file)

schtasks_delete(
  task_name,
  system = NULL,
  username = NULL,
  password = NULL,
  force = FALSE,
  quiet = FALSE
)

schtasks_query(
  system = NULL,
  username = NULL,
  password = NULL,
  format = c("csv", "list", "table"),
  no_header = FALSE,
  verbose = FALSE,
  raw = FALSE,
  xml_type = NULL,
  quiet = FALSE
)

schtasks_change(
  task_name,
  system = NULL,
  username = NULL,
  password = NULL,
  runas_username = NULL,
  runas_password = NULL,
  task_run = NULL,
  start_time = NULL,
  interval = NULL,
  end_time = NULL,
  duration = NULL,
  terminate = FALSE,
  start_date = NULL,
  end_date = NULL,
  level = NULL,
  enable = TRUE,
  disable = FALSE,
  delete_after_final = FALSE,
  delay_time = NULL,
  quiet = FALSE
)

schtasks_showsid(task_name, convert = TRUE)

Arguments

task_name

The path/name of the task to run now

system

The remote system to connect to

username

The user context under which the schtasks.exe should execute

password

The password for the given user context

quiet

If TRUE will suppress outputs

runas_username

The "run as" user account (user context) under which the tasks runs. For the system account, valid values are "", "NT AUTHORITY/SYSTEM", or "SYSTEM". For v2 tasks, "NT AUTHORITY/LOCALSERVICE" and "NT AUTHORITYNETWORKSERVICE" are also available as well as the well known SIDs for all three.

runas_password

The password for the "run as" user.

schedule

The schedule frequency. Valid schedule types are : minute, hourly, daily, weekly, monthly, once, on_start, on_logon, on_idle, and on_event

modifier

Refines the schedule type to allow finer control over schedule recurrence. See section Modifiers for more details.

days

The day of the week to run the task. Can be either the name of the week (or an abbreviation). If schedule is monthly can accept 1-31. Use * to specify all months.

months

The month(s) of the year. Defaults to the first of the month. Can use either the whole month (month.name) or month abbreviation (month.abb).

idle_time

The amount of idle time to wait before running a task. Only valid for schedule on_idle. Valid range from 1 to 999 (minutes).

task_run

A string in the form of the path/name which uniquely identifies the scheduled task

start_time

The start time to run the task. Time format is HH:mm (24 hour time). Can accept POSIXct or POSIXlt. Two special cases of "now" and "asap" are accepted; which are converted to the current time or the next minute, respectively.

interval

The repetition interval in minutes. Only applicable for daily, weekly, monthly, once. Valid ranges are 1 - 599940. If end_time or duration are specified, 10 is set as the default.

end_time

The end time to run the task. The time format is HH:mm (24 hour time). Not applicable for on_* schedules.

duration

The duration to run the task. The time format is HH:MM. This is not applicable with end_time. If v1 is TRUE and interval is set, the duration defaults to 01:00.

terminate

If TRUE, terminates the task at the end_time or duration time. This is not applicable for schedule types: on_start, on_logon, on_idle, and on_event.'

start_date

The first date on which the task runs. Not applicable for schedules once or on_*.

end_date

end_date The last date on which the task runs. Not applicable for schedules once or on_*.

channel_name

The event channel for on_event triggers

delete_after_final

If TRUE marks the task for deletion after its final run.

v1

If TRUE creates a task visible to pre-Vista platforms

force

If TRUE forcefully creates the task and suppresses cmd warnings if the task already exists.

level

The run level for the job, either limited or highest.

delay_time

The wait time to delay the running of the task after the trigger is fired. Time format is mmmm::ss. Only valid for schedules on_start, on_logon, and on_event.

xml_file

A path to a .xml file

format

The format for the output. One of: csv, list, or table

no_header

If TRUE, does not display

verbose

If TRUE displays the verbose task output

raw

If TRUE returns the raw output rather than a tibble

xml_type

Displays the task definitions in XML format. If xml_type is single then the output will be one valid XML file. If concat will concatenate all the XML definitions.

enable

If TRUE enables the scheduled task

disable

If TRUE disables the scheduled task

convert

Converts the output (currently only valid for show_sid)

Details

Commands are passed using base::system2()

Wrappers for R6 object creation and command execution:

schtasks_run()

Runs a scheduled task on demand

schtasks_end()

Stops a currently running scheduled task

schtasks_create()

Create a scheduled tasks on a local or remote system

schtasks_delete()

Deletes a scheduled task

schtasks_query()

Displays the scheduled tasks on the local or remote system. Returns a tibble

schtasks_change()

Changes the program to run, or user account and password used by a scheduled task

schtasks_showsid()

Shows the security identifier corresponding to a scheduled task name

Modifiers

Valid values for the modifiers are as follows:

monthly

1 - 12 or "first", "second", "third", "fourth", "last", or "last_day"

weekly

weeks 1 - 52

minute

1 - 1439 minutes

daily

1 - 365 days

hourly

1 - 23 hours

once

nothing

on_start

nothing

on_logon

nothing

on_idle

nothing

on_event

XPath event query string

schtasks.exe

These functions specifically make it easier to an R user on Windows to interact with the Schtasks.exe applications. Note that successful use of Schtasks.exe required Administrative privledged and should be run as an administrator. This will likely be an issue if the user is using Rstudio

Public fields

result

The the the call

system_call

The system call of the function

exec

Should schtasks.exe be executed? For testing purposes only.

Methods

Public methods


Method new()

Initializes the call

Usage
TaskScheduler$new(
  task_name = NULL,
  system = NULL,
  username = NULL,
  password = NULL,
  runas_username = NULL,
  runas_password = NULL,
  schedule = c("once", "minute", "hourly", "daily", "weekly", "monthly", "onstart",
    "onlogon", "onidle", "onevent"),
  modifier = NULL,
  days = NULL,
  months = NULL,
  idle_time = NULL,
  task_run = NULL,
  start_time = NULL,
  interval = NULL,
  end_time = NULL,
  duration = NULL,
  terminate = FALSE,
  start_date = NULL,
  end_date = NULL,
  channel_name = NULL,
  delete_after_final = FALSE,
  v1 = FALSE,
  force = FALSE,
  level = c("limited", "highest"),
  delay_time = NULL,
  xml_file = NULL,
  format = c("csv", "list", "table"),
  no_header = FALSE,
  verbose = FALSE,
  xml_type = NULL,
  raw = FALSE,
  enable = FALSE,
  disable = FALSE,
  env = "",
  convert = TRUE,
  quiet = FALSE,
  exec = TRUE
)
Arguments
env

character vector of name=value strings to set environment variables (passed to base::system2())

exec

If FALSE will not run base::system2()


Method run()

Runs schtasks run

Usage
TaskScheduler$run()

Method end()

Runs schtasks end

Usage
TaskScheduler$end()

Method create()

Runs schtasks create

Usage
TaskScheduler$create()

Method create_xml()

creates a task using an xml file, a special variant for schtasks create

Usage
TaskScheduler$create_xml()

Method delete()

Runs schtasks delete

Usage
TaskScheduler$delete()

Method query()

Runs schtasks query

Usage
TaskScheduler$query()

Method change()

Runs schtasks change

Usage
TaskScheduler$change()

Method show_sid()

Runs schtasks showsid check days check months check idle_time

Usage
TaskScheduler$show_sid()

Method clone()

The objects of this class are cloneable with this method.

Usage
TaskScheduler$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

## Not run: 
# These are recreations of the examples from the cmd help documents.  These
#   are nonsensical.

# Creates a scheduled task
# Creates a scheduled task "doc" on the remote machine "abc" which runs
#   notepad.exe every hour under user "runasuser"
schtasks_create(
  system = "abc",
  username = "user",
  password = "password",
  runas_username = "unasuer",
  runas_password = "runaspassword",
  schedule = "hourly",
  task_name = "doc",
  task_run = "notepad"
)

# Change a task
schtasks_change(
  password = "password",
  task_name = "/Backup/Backup and Restore"
)
schtasks_change(
  task_run = "restore.exe",
  task_name = "/Backup/Start Restore"
)

schtasks_change(
  system = "system",
  username = "user",
  password = "password",
  runas_username = "newuser",
  task_name = "/Backup/Start Backup"
)

# Query a task
schtasks_query(
  system = "system",
  username = "user",
  password = "password"
)

schtasks_query(
  format = "list",
  verbose = TRUE,
  system = "system",
  username = "user",
  password = "password"
)
schtasks_query(
  format = "table",
  no_header = TRUE,
  verbose = TRUE
)

## End(Not run)


jmbarbone/rschtasks documentation built on Sept. 4, 2022, 1:52 p.m.