summaryrefslogtreecommitdiffstats
path: root/toolkit/components/taskscheduler/nsIWinTaskSchedulerService.idl
blob: 7778360e7d5e122a8c837a009aa2779686d87a8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"

/**
 * An interface for Windows Task Scheduler 2.0.
 * Documentation for the underlying APIs can be found at
 * https://docs.microsoft.com/en-us/windows/win32/taskschd/task-scheduler-start-page
 */
[scriptable, main_process_scriptable_only, uuid(a8d36901-0b6a-46c3-a214-a9e1d5d6047a)]
interface nsIWinTaskSchedulerService : nsISupports
{
  /**
   * Register (create) a task from an XML definition.
   * The task will be created so that it only runs as the current user
   * (TASK_LOGON_INTERACTIVE_TOKEN).
   *
   * @throws NS_ERROR_FILE_NOT_FOUND if the folder does not exist.
   * @throws NS_ERROR_FILE_ALREADY_EXISTS if the task already existed and aUpdateExisting is false.
   *
   * @param aFolderName     Full name of the folder in which to create the task, starting with "\".
   *
   * @param aTaskName       Name of the task.
   *
   * @param aDefinitionXML  XML definition of the task. This is passed directly to Task Scheduler,
   *                        see the schema at
   *                        https://docs.microsoft.com/en-us/windows/win32/taskschd/task-scheduler-schema
   *
   * @param aUpdateExisting Whether to update an existing task with the same name, default false.
   */
  void registerTask(in wstring aFolderName,
                    in wstring aTaskName,
                    in wstring aDefinitionXML,
                    [optional] in boolean aUpdateExisting);

  /**
   * Validate the XML task definition with Task Scheduler without creating a task, for testing.
   * Doesn't throw if only the final ITaskFolder::RegisterTask() fails.
   *
   * @param aDefinitionXML      Definition to validate.
   * @return                    HRESULT from ITaskFolder::RegisterTask()
   *                            Success should be S_OK (0). XML validation failure could be one of
   *                            SCHED_E_UNEXPECTED_NODE, SCHED_E_NAMESPACE, SCHED_E_INVALIDVALUE,
   *                            SCHED_E_MISSINGNODE, SCHED_E_MALFORMEDXML, but there may be others.
   */
  long validateTaskDefinition(in wstring aDefinitionXML);

  /**
   * Get the registration information for a task.
   *
   * @throws NS_ERROR_FILE_NOT_FOUND if the folder or task do not exist.
   *
   * @param aFolderName     Full name of the folder containing the task, starting with "\".
   * @param aTaskName       Name of the task to read.
   * @return                Registration information for the task, as XML text.
   */
  AString getTaskXML(in wstring aFolderName, in wstring aTaskName);

  /**
   * Gets the sid of the current user.
   *
   * @throws NS_ERROR_NOT_IMPLEMENTED If called on a non-Windows OS.
   * @throws NS_ERROR_FAILURE         If the user token cannot be found.
   * @throws NS_ERROR_ABORT           If converting the sid to a string fails.
   *
   * @returns                         The sid of the current user.
   */
  AString getCurrentUserSid();

  /**
   * Delete a task.
   *
   * @throws NS_ERROR_FILE_NOT_FOUND if the folder or task do not exist.
   *
   * @param aFolderName     Full name of the folder containing the task, starting with "\".
   * @param aTaskName       Name of the task to delete.
   */
  void deleteTask(in wstring aFolderName, in wstring aTaskName);

  /**
   * List the names of all tasks in a task folder.
   *
   * @throws NS_ERROR_FILE_NOT_FOUND if the folder doesn't exist.
   *
   * @param aFolderName     The full name of the task folder to enumerate, starting with "\".
   *
   * @return                An array with the names of the tasks found.
   */
  Array<AString> getFolderTasks(in wstring aFolderName);

  /**
   * Create a new task subfolder under a given parent folder.
   *
   * @throws NS_ERROR_FILE_NOT_FOUND if the parent folder does not exist.
   * @throws NS_ERROR_FILE_ALREADY_EXISTS if the subfolder already exists.
   *
   * @param aParentFolderName       Immediate parent for the new folder, starting with "\".
   * @param aSubFolderName          Name of the new folder to create.
   */
  void createFolder(in wstring aParentFolderName, in wstring aSubFolderName);

  /**
   * Delete a folder.
   *
   * @throws NS_ERROR_FILE_NOT_FOUND if the parent folder does not exist.
   * @throws NS_ERROR_FILE_DIR_NOT_EMPTY if the folder was not empty.
   *
   * @param aParentFolderName       Immediate parent of the folder to delete, starting with "\".
   * @param aSubFolderName          Name of the folder to delete.
   */
  void deleteFolder(in wstring aParentFolderName, in wstring aSubFolderName);
};