ReactOS 0.4.15-dev-7918-g2a2556c
schtasks.c File Reference
#include "initguid.h"
#include "taskschd.h"
#include "wine/debug.h"
#include "wine/unicode.h"
Include dependency graph for schtasks.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (schtasks)
 
static ITaskFolder * get_tasks_root_folder (void)
 
static IRegisteredTask * get_registered_task (const WCHAR *name)
 
static BSTR read_file_to_bstr (const WCHAR *file_name)
 
static int change_command (int argc, WCHAR *argv[])
 
static int create_command (int argc, WCHAR *argv[])
 
static int delete_command (int argc, WCHAR *argv[])
 
int wmain (int argc, WCHAR *argv[])
 

Variables

static const WCHAR change_optW [] = {'/','c','h','a','n','g','e',0}
 
static const WCHAR create_optW [] = {'/','c','r','e','a','t','e',0}
 
static const WCHAR delete_optW [] = {'/','d','e','l','e','t','e',0}
 
static const WCHAR enable_optW [] = {'/','e','n','a','b','l','e',0}
 
static const WCHAR f_optW [] = {'/','f',0}
 
static const WCHAR ru_optW [] = {'/','r','u',0}
 
static const WCHAR tn_optW [] = {'/','t','n',0}
 
static const WCHAR tr_optW [] = {'/','t','r',0}
 
static const WCHAR xml_optW [] = {'/','x','m','l',0}
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 19 of file schtasks.c.

Function Documentation

◆ change_command()

static int change_command ( int  argc,
WCHAR argv[] 
)
static

Definition at line 136 of file schtasks.c.

137{
138 BOOL have_option = FALSE, enable = FALSE;
139 const WCHAR *task_name = NULL;
140 IRegisteredTask *task;
142
143 while (argc) {
144 if(!strcmpiW(argv[0], tn_optW)) {
145 if (argc < 2) {
146 FIXME("Missing /tn value\n");
147 return 1;
148 }
149
150 if (task_name) {
151 FIXME("Duplicated /tn argument\n");
152 return 1;
153 }
154
155 task_name = argv[1];
156 argc -= 2;
157 argv += 2;
158 }else if (!strcmpiW(argv[0], enable_optW)) {
159 enable = TRUE;
160 have_option = TRUE;
161 argc--;
162 argv++;
163 }else if (!strcmpiW(argv[0], tr_optW)) {
164 if (argc < 2) {
165 FIXME("Missing /tr value\n");
166 return 1;
167 }
168
169 FIXME("Unsupported /tr option %s\n", debugstr_w(argv[1]));
170 have_option = TRUE;
171 argc -= 2;
172 argv += 2;
173 }else {
174 FIXME("Unsupported arguments %s\n", debugstr_w(argv[0]));
175 return 1;
176 }
177 }
178
179 if (!task_name) {
180 FIXME("Missing /tn option\n");
181 return 1;
182 }
183
184 if (!have_option) {
185 FIXME("Missing change options\n");
186 return 1;
187 }
188
189 task = get_registered_task(task_name);
190 if (!task)
191 return 1;
192
193 if (enable) {
194 hres = IRegisteredTask_put_Enabled(task, VARIANT_TRUE);
195 if (FAILED(hres)) {
196 IRegisteredTask_Release(task);
197 FIXME("put_Enabled failed: %08x\n", hres);
198 return 1;
199 }
200 }
201
202 IRegisteredTask_Release(task);
203 return 0;
204}
static int argc
Definition: ServiceArgs.c:12
#define FIXME(fmt,...)
Definition: debug.h:111
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
GLboolean enable
Definition: glext.h:11120
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_w
Definition: kernel32.h:32
HRESULT hres
Definition: protocol.c:465
#define argv
Definition: mplay32.c:18
#define strcmpiW(s1, s2)
Definition: unicode.h:39
static IRegisteredTask * get_registered_task(const WCHAR *name)
Definition: schtasks.c:68
static const WCHAR tn_optW[]
Definition: schtasks.c:35
static const WCHAR enable_optW[]
Definition: schtasks.c:32
static const WCHAR tr_optW[]
Definition: schtasks.c:36
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by wmain().

◆ create_command()

static int create_command ( int  argc,
WCHAR argv[] 
)
static

Definition at line 206 of file schtasks.c.

207{
208 const WCHAR *task_name = NULL, *xml_file = NULL;
209 ITaskFolder *root = NULL;
211 IRegisteredTask *task;
213 BSTR str, xml;
215
216 while (argc) {
217 if (!strcmpiW(argv[0], xml_optW)) {
218 if (argc < 2) {
219 FIXME("Missing /xml value\n");
220 return 1;
221 }
222
223 if (xml_file) {
224 FIXME("Duplicated /xml argument\n");
225 return 1;
226 }
227
228 xml_file = argv[1];
229 argc -= 2;
230 argv += 2;
231 }else if(!strcmpiW(argv[0], tn_optW)) {
232 if (argc < 2) {
233 FIXME("Missing /tn value\n");
234 return 1;
235 }
236
237 if (task_name) {
238 FIXME("Duplicated /tn argument\n");
239 return 1;
240 }
241
242 task_name = argv[1];
243 argc -= 2;
244 argv += 2;
245 }else if(!strcmpiW(argv[0], f_optW)) {
247 argc--;
248 argv++;
249 }else if (!strcmpiW(argv[0], ru_optW)) {
250 if (argc < 2) {
251 FIXME("Missing /ru value\n");
252 return 1;
253 }
254
255 FIXME("Unsupported /ru option %s\n", debugstr_w(argv[1]));
256 argc -= 2;
257 argv += 2;
258 }else {
259 FIXME("Unsupported argument %s\n", debugstr_w(argv[0]));
260 return 1;
261 }
262 }
263
264 if (!task_name) {
265 FIXME("Missing /tn argument\n");
266 return 1;
267 }
268
269 if (!xml_file) {
270 FIXME("Missing /xml argument\n");
271 return E_FAIL;
272 }
273
274 xml = read_file_to_bstr(xml_file);
275 if (!xml)
276 return 1;
277
279 if (!root) {
280 SysFreeString(xml);
281 return 1;
282 }
283
284 V_VT(&empty) = VT_EMPTY;
285 str = SysAllocString(task_name);
286 hres = ITaskFolder_RegisterTask(root, str, xml, flags, empty, empty,
287 TASK_LOGON_NONE, empty, &task);
289 SysFreeString(xml);
290 ITaskFolder_Release(root);
291 if (FAILED(hres))
292 return 1;
293
294 IRegisteredTask_Release(task);
295 return 0;
296}
#define E_FAIL
Definition: ddrawi.h:102
static const WCHAR empty[]
Definition: main.c:47
OLECHAR * BSTR
Definition: compat.h:2293
@ VT_EMPTY
Definition: compat.h:2295
GLbitfield flags
Definition: glext.h:7161
@ TASK_CREATE_OR_UPDATE
Definition: taskschd.idl:107
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
#define V_VT(A)
Definition: oleauto.h:211
long LONG
Definition: pedump.c:60
const WCHAR * str
static BSTR read_file_to_bstr(const WCHAR *file_name)
Definition: schtasks.c:91
static ITaskFolder * get_tasks_root_folder(void)
Definition: schtasks.c:39
static const WCHAR ru_optW[]
Definition: schtasks.c:34
static const WCHAR xml_optW[]
Definition: schtasks.c:37
static const WCHAR f_optW[]
Definition: schtasks.c:33

Referenced by wmain().

◆ delete_command()

static int delete_command ( int  argc,
WCHAR argv[] 
)
static

Definition at line 298 of file schtasks.c.

299{
300 const WCHAR *task_name = NULL;
301 ITaskFolder *root = NULL;
302 BSTR str;
304
305 while (argc) {
306 if (!strcmpiW(argv[0], f_optW)) {
307 TRACE("force opt\n");
308 argc--;
309 argv++;
310 }else if(!strcmpiW(argv[0], tn_optW)) {
311 if (argc < 2) {
312 FIXME("Missing /tn value\n");
313 return 1;
314 }
315
316 if (task_name) {
317 FIXME("Duplicated /tn argument\n");
318 return 1;
319 }
320
321 task_name = argv[1];
322 argc -= 2;
323 argv += 2;
324 }else {
325 FIXME("Unsupported argument %s\n", debugstr_w(argv[0]));
326 return 1;
327 }
328 }
329
330 if (!task_name) {
331 FIXME("Missing /tn argument\n");
332 return 1;
333 }
334
336 if (!root)
337 return 1;
338
339 str = SysAllocString(task_name);
340 hres = ITaskFolder_DeleteTask(root, str, 0);
342 ITaskFolder_Release(root);
343 if (FAILED(hres))
344 return 1;
345
346 return 0;
347}
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by wmain().

◆ get_registered_task()

static IRegisteredTask * get_registered_task ( const WCHAR name)
static

Definition at line 68 of file schtasks.c.

69{
70 IRegisteredTask *registered_task;
71 ITaskFolder *root;
72 BSTR str;
74
76 if (!root)
77 return NULL;
78
80 hres = ITaskFolder_GetTask(root, str, &registered_task);
82 ITaskFolder_Release(root);
83 if (FAILED(hres)) {
84 FIXME("GetTask failed: %08x\n", hres);
85 return NULL;
86 }
87
88 return registered_task;
89}
struct _root root
Definition: name.c:39

Referenced by change_command().

◆ get_tasks_root_folder()

static ITaskFolder * get_tasks_root_folder ( void  )
static

Definition at line 39 of file schtasks.c.

40{
41 ITaskService *service;
42 ITaskFolder *root;
45
46 hres = CoCreateInstance(&CLSID_TaskScheduler, NULL, CLSCTX_INPROC_SERVER,
47 &IID_ITaskService, (void**)&service);
48 if (FAILED(hres))
49 return NULL;
50
52 hres = ITaskService_Connect(service, empty, empty, empty, empty);
53 if (FAILED(hres)) {
54 FIXME("Connect failed: %08x\n", hres);
55 return NULL;
56 }
57
58 hres = ITaskService_GetFolder(service, NULL, &root);
59 ITaskService_Release(service);
60 if (FAILED(hres)) {
61 FIXME("GetFolder failed: %08x\n", hres);
62 return NULL;
63 }
64
65 return root;
66}
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325

Referenced by create_command(), delete_command(), and get_registered_task().

◆ read_file_to_bstr()

static BSTR read_file_to_bstr ( const WCHAR file_name)
static

Definition at line 91 of file schtasks.c.

92{
94 DWORD read_size, size;
95 unsigned char *data;
97 BOOL r = FALSE;
98 BSTR ret;
99
102 if (file == INVALID_HANDLE_VALUE) {
103 FIXME("Could not open file\n");
104 return NULL;
105 }
106
107 if (!GetFileSizeEx(file, &file_size) || !file_size.QuadPart) {
108 FIXME("Empty file\n");
110 return NULL;
111 }
112
113 data = HeapAlloc(GetProcessHeap(), 0, file_size.QuadPart);
114 if (data)
115 r = ReadFile(file, data, file_size.QuadPart, &read_size, NULL);
117 if (!r) {
118 FIXME("Read filed\n");
120 return NULL;
121 }
122
123 if (read_size > 2 && data[0] == 0xff && data[1] == 0xfe) { /* UTF-16 BOM */
124 ret = SysAllocStringLen((const WCHAR *)(data + 2), (read_size - 2) / sizeof(WCHAR));
125 }else {
126 size = MultiByteToWideChar(CP_ACP, 0, (const char *)data, read_size, NULL, 0);
128 if (ret)
129 MultiByteToWideChar(CP_ACP, 0, (const char *)data, read_size, ret, size);
130 }
132
133 return ret;
134}
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define CP_ACP
Definition: compat.h:109
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define GENERIC_READ
Definition: compat.h:135
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CreateFileW
Definition: compat.h:741
#define GetFileSizeEx
Definition: compat.h:757
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define MultiByteToWideChar
Definition: compat.h:110
#define FILE_SHARE_READ
Definition: compat.h:136
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLsizeiptr size
Definition: glext.h:5919
static LPCWSTR file_name
Definition: protocol.c:147
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:339
static unsigned int file_size
Definition: regtests2xml.c:47
Definition: fci.c:127
int ret

Referenced by create_command().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( schtasks  )

◆ wmain()

int wmain ( int  argc,
WCHAR argv[] 
)

Definition at line 349 of file schtasks.c.

350{
351 int i, ret = 0;
352
353 for (i = 0; i < argc; i++)
354 TRACE(" %s", wine_dbgstr_w(argv[i]));
355 TRACE("\n");
356
358
359 if (argc < 2)
360 FIXME("Print current tasks state\n");
361 else if (!strcmpiW(argv[1], change_optW))
362 ret = change_command(argc - 2, argv + 2);
363 else if (!strcmpiW(argv[1], create_optW))
364 ret = create_command(argc - 2, argv + 2);
365 else if (!strcmpiW(argv[1], delete_optW))
366 ret = delete_command(argc - 2, argv + 2);
367 else
368 FIXME("Unsupported command %s\n", debugstr_w(argv[1]));
369
371 return ret;
372}
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define wine_dbgstr_w
Definition: kernel32.h:34
static int delete_command(int argc, WCHAR *argv[])
Definition: schtasks.c:298
static int change_command(int argc, WCHAR *argv[])
Definition: schtasks.c:136
static int create_command(int argc, WCHAR *argv[])
Definition: schtasks.c:206
static const WCHAR delete_optW[]
Definition: schtasks.c:31
static const WCHAR change_optW[]
Definition: schtasks.c:29
static const WCHAR create_optW[]
Definition: schtasks.c:30

Variable Documentation

◆ change_optW

const WCHAR change_optW[] = {'/','c','h','a','n','g','e',0}
static

Definition at line 29 of file schtasks.c.

Referenced by wmain().

◆ create_optW

const WCHAR create_optW[] = {'/','c','r','e','a','t','e',0}
static

Definition at line 30 of file schtasks.c.

Referenced by wmain().

◆ delete_optW

const WCHAR delete_optW[] = {'/','d','e','l','e','t','e',0}
static

Definition at line 31 of file schtasks.c.

Referenced by wmain().

◆ enable_optW

const WCHAR enable_optW[] = {'/','e','n','a','b','l','e',0}
static

Definition at line 32 of file schtasks.c.

Referenced by change_command().

◆ f_optW

const WCHAR f_optW[] = {'/','f',0}
static

Definition at line 33 of file schtasks.c.

Referenced by create_command(), and delete_command().

◆ ru_optW

const WCHAR ru_optW[] = {'/','r','u',0}
static

Definition at line 34 of file schtasks.c.

Referenced by create_command().

◆ tn_optW

const WCHAR tn_optW[] = {'/','t','n',0}
static

Definition at line 35 of file schtasks.c.

Referenced by change_command(), create_command(), and delete_command().

◆ tr_optW

const WCHAR tr_optW[] = {'/','t','r',0}
static

Definition at line 36 of file schtasks.c.

Referenced by change_command().

◆ xml_optW

const WCHAR xml_optW[] = {'/','x','m','l',0}
static

Definition at line 37 of file schtasks.c.

Referenced by create_command().