2008-08-04 20:43:21 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Google (Roy Shea)
|
2018-03-13 09:04:07 +01:00
|
|
|
* Copyright (C) 2018 Dmitry Timoshkov
|
2008-08-04 20:43:21 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2018-03-13 09:04:01 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2018-05-14 09:49:25 +02:00
|
|
|
#include "winternl.h"
|
2018-03-13 09:04:01 +01:00
|
|
|
#include "objbase.h"
|
2018-03-13 09:04:07 +01:00
|
|
|
#include "taskschd.h"
|
2018-03-13 09:04:01 +01:00
|
|
|
#include "mstask.h"
|
2008-08-04 20:43:21 +02:00
|
|
|
#include "mstask_private.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mstask);
|
|
|
|
|
2018-04-20 10:37:31 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
USHORT product_version;
|
|
|
|
USHORT file_version;
|
|
|
|
UUID uuid;
|
|
|
|
USHORT name_size_offset;
|
|
|
|
USHORT trigger_offset;
|
|
|
|
USHORT error_retry_count;
|
|
|
|
USHORT error_retry_interval;
|
|
|
|
USHORT idle_deadline;
|
|
|
|
USHORT idle_wait;
|
|
|
|
UINT priority;
|
|
|
|
UINT maximum_runtime;
|
|
|
|
UINT exit_code;
|
|
|
|
HRESULT status;
|
|
|
|
UINT flags;
|
|
|
|
SYSTEMTIME last_runtime;
|
|
|
|
} FIXDLEN_DATA;
|
|
|
|
|
2011-01-24 00:17:58 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
ITask ITask_iface;
|
|
|
|
IPersistFile IPersistFile_iface;
|
|
|
|
LONG ref;
|
2018-03-30 10:58:18 +02:00
|
|
|
ITaskDefinition *task;
|
2018-03-30 10:59:47 +02:00
|
|
|
IExecAction *action;
|
2018-05-24 10:29:26 +02:00
|
|
|
UUID uuid;
|
2018-03-30 10:58:18 +02:00
|
|
|
LPWSTR task_name;
|
2018-04-20 10:37:08 +02:00
|
|
|
HRESULT status;
|
2018-04-20 10:37:18 +02:00
|
|
|
WORD idle_minutes, deadline_minutes;
|
2018-05-15 10:26:52 +02:00
|
|
|
DWORD flags, priority, maxRunTime, exit_code;
|
2018-05-31 06:20:14 +02:00
|
|
|
SYSTEMTIME last_runtime;
|
2011-01-24 00:17:58 +01:00
|
|
|
LPWSTR accountName;
|
2018-04-24 10:13:43 +02:00
|
|
|
DWORD trigger_count;
|
2018-04-24 10:13:47 +02:00
|
|
|
TASK_TRIGGER *trigger;
|
2018-04-26 07:46:52 +02:00
|
|
|
BOOL is_dirty;
|
2018-05-11 06:36:31 +02:00
|
|
|
USHORT instance_count;
|
2011-01-24 00:17:58 +01:00
|
|
|
} TaskImpl;
|
|
|
|
|
|
|
|
static inline TaskImpl *impl_from_ITask(ITask *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, TaskImpl, ITask_iface);
|
|
|
|
}
|
|
|
|
|
2008-08-21 17:54:01 +02:00
|
|
|
static inline TaskImpl *impl_from_IPersistFile( IPersistFile *iface )
|
|
|
|
{
|
2011-01-24 00:17:58 +01:00
|
|
|
return CONTAINING_RECORD(iface, TaskImpl, IPersistFile_iface);
|
2008-08-21 17:54:01 +02:00
|
|
|
}
|
|
|
|
|
2008-08-04 20:43:21 +02:00
|
|
|
static void TaskDestructor(TaskImpl *This)
|
|
|
|
{
|
|
|
|
TRACE("%p\n", This);
|
2018-03-30 10:59:47 +02:00
|
|
|
if (This->action)
|
|
|
|
IExecAction_Release(This->action);
|
2018-03-30 10:58:18 +02:00
|
|
|
ITaskDefinition_Release(This->task);
|
2018-04-26 07:46:46 +02:00
|
|
|
heap_free(This->task_name);
|
|
|
|
heap_free(This->accountName);
|
|
|
|
heap_free(This->trigger);
|
|
|
|
heap_free(This);
|
2008-08-04 20:43:21 +02:00
|
|
|
InterlockedDecrement(&dll_ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITask_QueryInterface(
|
|
|
|
ITask* iface,
|
|
|
|
REFIID riid,
|
|
|
|
void **ppvObject)
|
|
|
|
{
|
2011-01-24 00:17:58 +01:00
|
|
|
TaskImpl * This = impl_from_ITask(iface);
|
2008-08-04 20:43:21 +02:00
|
|
|
|
|
|
|
TRACE("IID: %s\n", debugstr_guid(riid));
|
|
|
|
if (ppvObject == NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualGUID(riid, &IID_ITask))
|
|
|
|
{
|
2011-01-24 00:17:58 +01:00
|
|
|
*ppvObject = &This->ITask_iface;
|
2008-08-04 20:43:21 +02:00
|
|
|
ITask_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2008-08-21 17:54:01 +02:00
|
|
|
else if (IsEqualGUID(riid, &IID_IPersistFile))
|
|
|
|
{
|
2011-01-24 00:17:58 +01:00
|
|
|
*ppvObject = &This->IPersistFile_iface;
|
2008-08-21 17:54:01 +02:00
|
|
|
ITask_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2008-08-04 20:43:21 +02:00
|
|
|
|
|
|
|
WARN("Unknown interface: %s\n", debugstr_guid(riid));
|
|
|
|
*ppvObject = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MSTASK_ITask_AddRef(
|
|
|
|
ITask* iface)
|
|
|
|
{
|
2011-01-24 00:17:58 +01:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
2008-08-04 20:43:21 +02:00
|
|
|
ULONG ref;
|
|
|
|
TRACE("\n");
|
|
|
|
ref = InterlockedIncrement(&This->ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MSTASK_ITask_Release(
|
|
|
|
ITask* iface)
|
|
|
|
{
|
2011-01-24 00:17:58 +01:00
|
|
|
TaskImpl * This = impl_from_ITask(iface);
|
2008-08-04 20:43:21 +02:00
|
|
|
ULONG ref;
|
|
|
|
TRACE("\n");
|
|
|
|
ref = InterlockedDecrement(&This->ref);
|
|
|
|
if (ref == 0)
|
|
|
|
TaskDestructor(This);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2018-05-14 09:49:25 +02:00
|
|
|
HRESULT task_set_trigger(ITask *task, WORD idx, const TASK_TRIGGER *src)
|
|
|
|
{
|
|
|
|
TaskImpl *This = impl_from_ITask(task);
|
|
|
|
TIME_FIELDS field_time;
|
|
|
|
LARGE_INTEGER sys_time;
|
|
|
|
TASK_TRIGGER dst;
|
|
|
|
|
|
|
|
TRACE("(%p, %u, %p)\n", task, idx, src);
|
|
|
|
|
|
|
|
if (idx >= This->trigger_count)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
/* Verify valid structure size */
|
|
|
|
if (src->cbTriggerSize != sizeof(*src))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
dst.cbTriggerSize = src->cbTriggerSize;
|
|
|
|
|
|
|
|
/* Reserved field must be zero */
|
|
|
|
dst.Reserved1 = 0;
|
|
|
|
|
|
|
|
/* Verify and set valid start date and time */
|
|
|
|
memset(&field_time, 0, sizeof(field_time));
|
|
|
|
field_time.Year = src->wBeginYear;
|
|
|
|
field_time.Month = src->wBeginMonth;
|
|
|
|
field_time.Day = src->wBeginDay;
|
|
|
|
field_time.Hour = src->wStartHour;
|
|
|
|
field_time.Minute = src->wStartMinute;
|
|
|
|
if (!RtlTimeFieldsToTime(&field_time, &sys_time))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
dst.wBeginYear = src->wBeginYear;
|
|
|
|
dst.wBeginMonth = src->wBeginMonth;
|
|
|
|
dst.wBeginDay = src->wBeginDay;
|
|
|
|
dst.wStartHour = src->wStartHour;
|
|
|
|
dst.wStartMinute = src->wStartMinute;
|
|
|
|
|
|
|
|
/* Verify valid end date if TASK_TRIGGER_FLAG_HAS_END_DATE flag is set */
|
|
|
|
if (src->rgFlags & TASK_TRIGGER_FLAG_HAS_END_DATE)
|
|
|
|
{
|
|
|
|
memset(&field_time, 0, sizeof(field_time));
|
|
|
|
field_time.Year = src->wEndYear;
|
|
|
|
field_time.Month = src->wEndMonth;
|
|
|
|
field_time.Day = src->wEndDay;
|
|
|
|
if (!RtlTimeFieldsToTime(&field_time, &sys_time))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set valid end date independent of TASK_TRIGGER_FLAG_HAS_END_DATE flag */
|
|
|
|
dst.wEndYear = src->wEndYear;
|
|
|
|
dst.wEndMonth = src->wEndMonth;
|
|
|
|
dst.wEndDay = src->wEndDay;
|
|
|
|
|
|
|
|
/* Verify duration and interval pair */
|
|
|
|
if (src->MinutesDuration <= src->MinutesInterval && src->MinutesInterval > 0)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
dst.MinutesDuration = src->MinutesDuration;
|
|
|
|
dst.MinutesInterval = src->MinutesInterval;
|
|
|
|
|
|
|
|
/* Copy over flags */
|
|
|
|
dst.rgFlags = src->rgFlags;
|
|
|
|
|
|
|
|
/* Set TriggerType dependent fields of Type union */
|
|
|
|
dst.TriggerType = src->TriggerType;
|
|
|
|
switch (src->TriggerType)
|
|
|
|
{
|
|
|
|
case TASK_TIME_TRIGGER_DAILY:
|
|
|
|
dst.Type.Daily.DaysInterval = src->Type.Daily.DaysInterval;
|
|
|
|
break;
|
|
|
|
case TASK_TIME_TRIGGER_WEEKLY:
|
|
|
|
dst.Type.Weekly.WeeksInterval = src->Type.Weekly.WeeksInterval;
|
|
|
|
dst.Type.Weekly.rgfDaysOfTheWeek = src->Type.Weekly.rgfDaysOfTheWeek;
|
|
|
|
break;
|
|
|
|
case TASK_TIME_TRIGGER_MONTHLYDATE:
|
|
|
|
dst.Type.MonthlyDate.rgfDays = src->Type.MonthlyDate.rgfDays;
|
|
|
|
dst.Type.MonthlyDate.rgfMonths = src->Type.MonthlyDate.rgfMonths;
|
|
|
|
break;
|
|
|
|
case TASK_TIME_TRIGGER_MONTHLYDOW:
|
|
|
|
dst.Type.MonthlyDOW.wWhichWeek = src->Type.MonthlyDOW.wWhichWeek;
|
|
|
|
dst.Type.MonthlyDOW.rgfDaysOfTheWeek = src->Type.MonthlyDOW.rgfDaysOfTheWeek;
|
|
|
|
dst.Type.MonthlyDOW.rgfMonths = src->Type.MonthlyDOW.rgfMonths;
|
|
|
|
break;
|
|
|
|
case TASK_TIME_TRIGGER_ONCE:
|
|
|
|
case TASK_EVENT_TRIGGER_ON_IDLE:
|
|
|
|
case TASK_EVENT_TRIGGER_AT_SYSTEMSTART:
|
|
|
|
case TASK_EVENT_TRIGGER_AT_LOGON:
|
|
|
|
default:
|
|
|
|
dst.Type = src->Type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reserved field must be zero */
|
|
|
|
dst.Reserved2 = 0;
|
|
|
|
|
|
|
|
/* wRandomMinutesInterval not currently used and is initialized to zero */
|
|
|
|
dst.wRandomMinutesInterval = 0;
|
|
|
|
|
|
|
|
This->trigger[idx] = dst;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT task_get_trigger(ITask *task, WORD idx, TASK_TRIGGER *dst)
|
|
|
|
{
|
|
|
|
TaskImpl *This = impl_from_ITask(task);
|
|
|
|
TASK_TRIGGER *src;
|
|
|
|
|
|
|
|
TRACE("(%p, %u, %p)\n", task, idx, dst);
|
|
|
|
|
|
|
|
if (idx >= This->trigger_count)
|
|
|
|
return SCHED_E_TRIGGER_NOT_FOUND;
|
|
|
|
|
|
|
|
src = &This->trigger[idx];
|
|
|
|
|
|
|
|
/* Native implementation doesn't verify equivalent cbTriggerSize fields */
|
|
|
|
|
|
|
|
/* Copy relevant fields of the structure */
|
|
|
|
dst->cbTriggerSize = src->cbTriggerSize;
|
|
|
|
dst->Reserved1 = 0;
|
|
|
|
dst->wBeginYear = src->wBeginYear;
|
|
|
|
dst->wBeginMonth = src->wBeginMonth;
|
|
|
|
dst->wBeginDay = src->wBeginDay;
|
|
|
|
dst->wEndYear = src->wEndYear;
|
|
|
|
dst->wEndMonth = src->wEndMonth;
|
|
|
|
dst->wEndDay = src->wEndDay;
|
|
|
|
dst->wStartHour = src->wStartHour;
|
|
|
|
dst->wStartMinute = src->wStartMinute;
|
|
|
|
dst->MinutesDuration = src->MinutesDuration;
|
|
|
|
dst->MinutesInterval = src->MinutesInterval;
|
|
|
|
dst->rgFlags = src->rgFlags;
|
|
|
|
dst->TriggerType = src->TriggerType;
|
|
|
|
switch (src->TriggerType)
|
|
|
|
{
|
|
|
|
case TASK_TIME_TRIGGER_DAILY:
|
|
|
|
dst->Type.Daily.DaysInterval = src->Type.Daily.DaysInterval;
|
|
|
|
break;
|
|
|
|
case TASK_TIME_TRIGGER_WEEKLY:
|
|
|
|
dst->Type.Weekly.WeeksInterval = src->Type.Weekly.WeeksInterval;
|
|
|
|
dst->Type.Weekly.rgfDaysOfTheWeek = src->Type.Weekly.rgfDaysOfTheWeek;
|
|
|
|
break;
|
|
|
|
case TASK_TIME_TRIGGER_MONTHLYDATE:
|
|
|
|
dst->Type.MonthlyDate.rgfDays = src->Type.MonthlyDate.rgfDays;
|
|
|
|
dst->Type.MonthlyDate.rgfMonths = src->Type.MonthlyDate.rgfMonths;
|
|
|
|
break;
|
|
|
|
case TASK_TIME_TRIGGER_MONTHLYDOW:
|
|
|
|
dst->Type.MonthlyDOW.wWhichWeek = src->Type.MonthlyDOW.wWhichWeek;
|
|
|
|
dst->Type.MonthlyDOW.rgfDaysOfTheWeek = src->Type.MonthlyDOW.rgfDaysOfTheWeek;
|
|
|
|
dst->Type.MonthlyDOW.rgfMonths = src->Type.MonthlyDOW.rgfMonths;
|
|
|
|
break;
|
|
|
|
case TASK_TIME_TRIGGER_ONCE:
|
|
|
|
case TASK_EVENT_TRIGGER_ON_IDLE:
|
|
|
|
case TASK_EVENT_TRIGGER_AT_SYSTEMSTART:
|
|
|
|
case TASK_EVENT_TRIGGER_AT_LOGON:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dst->Reserved2 = 0;
|
|
|
|
dst->wRandomMinutesInterval = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-04-24 10:13:47 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_CreateTrigger(ITask *iface, WORD *idx, ITaskTrigger **task_trigger)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-04-24 10:13:47 +02:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
|
|
|
TASK_TRIGGER *new_trigger;
|
2018-05-14 09:49:25 +02:00
|
|
|
SYSTEMTIME time;
|
2018-04-24 10:13:47 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %p)\n", iface, idx, task_trigger);
|
|
|
|
|
2018-05-14 09:49:25 +02:00
|
|
|
hr = TaskTriggerConstructor(iface, This->trigger_count, task_trigger);
|
2018-04-24 10:13:47 +02:00
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
|
|
|
if (This->trigger)
|
|
|
|
new_trigger = heap_realloc(This->trigger, sizeof(This->trigger[0]) * (This->trigger_count + 1));
|
|
|
|
else
|
|
|
|
new_trigger = heap_alloc(sizeof(This->trigger[0]));
|
|
|
|
if (!new_trigger)
|
|
|
|
{
|
|
|
|
ITaskTrigger_Release(*task_trigger);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->trigger = new_trigger;
|
|
|
|
|
2018-05-14 09:49:25 +02:00
|
|
|
new_trigger = &This->trigger[This->trigger_count];
|
|
|
|
|
|
|
|
/* Most fields default to zero. Initialize other fields to default values. */
|
|
|
|
memset(new_trigger, 0, sizeof(*new_trigger));
|
|
|
|
GetLocalTime(&time);
|
|
|
|
new_trigger->cbTriggerSize = sizeof(*new_trigger);
|
|
|
|
new_trigger->wBeginYear = time.wYear;
|
|
|
|
new_trigger->wBeginMonth = time.wMonth;
|
|
|
|
new_trigger->wBeginDay = time.wDay;
|
|
|
|
new_trigger->wStartHour = time.wHour;
|
|
|
|
new_trigger->wStartMinute = time.wMinute;
|
|
|
|
new_trigger->rgFlags = TASK_TRIGGER_FLAG_DISABLED;
|
|
|
|
new_trigger->TriggerType = TASK_TIME_TRIGGER_DAILY,
|
|
|
|
new_trigger->Type.Daily.DaysInterval = 1;
|
|
|
|
|
|
|
|
*idx = This->trigger_count++;
|
2018-04-24 10:13:47 +02:00
|
|
|
|
|
|
|
return hr;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-04-24 10:13:51 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_DeleteTrigger(ITask *iface, WORD idx)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-04-24 10:13:51 +02:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
|
|
|
|
|
|
|
TRACE("(%p, %u)\n", iface, idx);
|
|
|
|
|
|
|
|
if (idx >= This->trigger_count)
|
|
|
|
return SCHED_E_TRIGGER_NOT_FOUND;
|
|
|
|
|
|
|
|
This->trigger_count--;
|
|
|
|
memmove(&This->trigger[idx], &This->trigger[idx + 1], (This->trigger_count - idx) * sizeof(This->trigger[0]));
|
|
|
|
/* this shouldn't fail in practice since we're shrinking the memory block */
|
|
|
|
This->trigger = heap_realloc(This->trigger, sizeof(This->trigger[0]) * This->trigger_count);
|
|
|
|
|
|
|
|
return S_OK;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-04-24 10:13:43 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetTriggerCount(ITask *iface, WORD *count)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-04-24 10:13:43 +02:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", iface, count);
|
|
|
|
|
|
|
|
*count = This->trigger_count;
|
|
|
|
return S_OK;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-04-24 10:13:58 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetTrigger(ITask *iface, WORD idx, ITaskTrigger **trigger)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-04-24 10:13:58 +02:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
|
|
|
|
|
|
|
TRACE("(%p, %u, %p)\n", iface, idx, trigger);
|
|
|
|
|
|
|
|
if (idx >= This->trigger_count)
|
|
|
|
return SCHED_E_TRIGGER_NOT_FOUND;
|
|
|
|
|
2018-05-14 09:49:25 +02:00
|
|
|
return TaskTriggerConstructor(iface, idx, trigger);
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetTriggerString(
|
|
|
|
ITask* iface,
|
|
|
|
WORD iTrigger,
|
|
|
|
LPWSTR *ppwszTrigger)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %d, %p): stub\n", iface, iTrigger, ppwszTrigger);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetRunTimes(
|
|
|
|
ITask* iface,
|
|
|
|
const LPSYSTEMTIME pstBegin,
|
|
|
|
const LPSYSTEMTIME pstEnd,
|
|
|
|
WORD *pCount,
|
|
|
|
LPSYSTEMTIME *rgstTaskTimes)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p, %p, %p, %p): stub\n", iface, pstBegin, pstEnd, pCount,
|
|
|
|
rgstTaskTimes);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-05-21 12:17:47 +02:00
|
|
|
static void get_begin_time(const TASK_TRIGGER *trigger, FILETIME *ft)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-05-21 12:17:47 +02:00
|
|
|
SYSTEMTIME st;
|
|
|
|
|
|
|
|
st.wYear = trigger->wBeginYear;
|
|
|
|
st.wMonth = trigger->wBeginMonth;
|
|
|
|
st.wDay = trigger->wBeginDay;
|
|
|
|
st.wDayOfWeek = 0;
|
|
|
|
st.wHour = 0;
|
|
|
|
st.wMinute = 0;
|
|
|
|
st.wSecond = 0;
|
|
|
|
st.wMilliseconds = 0;
|
|
|
|
SystemTimeToFileTime(&st, ft);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_end_time(const TASK_TRIGGER *trigger, FILETIME *ft)
|
|
|
|
{
|
|
|
|
SYSTEMTIME st;
|
|
|
|
|
|
|
|
if (!(trigger->rgFlags & TASK_TRIGGER_FLAG_HAS_END_DATE))
|
|
|
|
{
|
|
|
|
ft->dwHighDateTime = ~0u;
|
|
|
|
ft->dwLowDateTime = ~0u;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
st.wYear = trigger->wEndYear;
|
|
|
|
st.wMonth = trigger->wEndMonth;
|
|
|
|
st.wDay = trigger->wEndDay;
|
|
|
|
st.wDayOfWeek = 0;
|
|
|
|
st.wHour = 0;
|
|
|
|
st.wMinute = 0;
|
|
|
|
st.wSecond = 0;
|
|
|
|
st.wMilliseconds = 0;
|
|
|
|
SystemTimeToFileTime(&st, ft);
|
|
|
|
}
|
|
|
|
|
2018-05-21 12:17:49 +02:00
|
|
|
static void filetime_add_ms(FILETIME *ft, ULONGLONG ms)
|
|
|
|
{
|
|
|
|
union u_ftll
|
|
|
|
{
|
|
|
|
FILETIME ft;
|
|
|
|
ULONGLONG ll;
|
|
|
|
} *ftll = (union u_ftll *)ft;
|
|
|
|
|
|
|
|
ftll->ll += ms * (ULONGLONG)10000;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void filetime_add_hours(FILETIME *ft, ULONG hours)
|
|
|
|
{
|
|
|
|
filetime_add_ms(ft, (ULONGLONG)hours * 60 * 60 * 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void filetime_add_days(FILETIME *ft, ULONG days)
|
|
|
|
{
|
|
|
|
filetime_add_hours(ft, (ULONGLONG)days * 24);
|
|
|
|
}
|
|
|
|
|
2018-05-22 10:18:44 +02:00
|
|
|
static void filetime_add_weeks(FILETIME *ft, ULONG weeks)
|
|
|
|
{
|
|
|
|
filetime_add_days(ft, (ULONGLONG)weeks * 7);
|
|
|
|
}
|
|
|
|
|
2018-05-21 12:17:47 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetNextRunTime(ITask *iface, SYSTEMTIME *rt)
|
|
|
|
{
|
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
2018-05-22 10:18:36 +02:00
|
|
|
HRESULT hr = SCHED_S_TASK_NO_VALID_TRIGGERS;
|
2018-05-21 12:17:47 +02:00
|
|
|
SYSTEMTIME st, current_st;
|
|
|
|
FILETIME current_ft, begin_ft, end_ft, best_ft;
|
|
|
|
BOOL have_best_time = FALSE;
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", iface, rt);
|
|
|
|
|
2018-05-22 10:18:30 +02:00
|
|
|
if (This->flags & TASK_FLAG_DISABLED)
|
|
|
|
{
|
|
|
|
memset(rt, 0, sizeof(*rt));
|
|
|
|
return SCHED_S_TASK_DISABLED;
|
|
|
|
}
|
|
|
|
|
2018-05-21 12:17:47 +02:00
|
|
|
GetLocalTime(¤t_st);
|
|
|
|
|
|
|
|
for (i = 0; i < This->trigger_count; i++)
|
|
|
|
{
|
|
|
|
if (!(This->trigger[i].rgFlags & TASK_TRIGGER_FLAG_DISABLED))
|
|
|
|
{
|
|
|
|
get_begin_time(&This->trigger[i], &begin_ft);
|
|
|
|
get_end_time(&This->trigger[i], &end_ft);
|
|
|
|
|
|
|
|
switch (This->trigger[i].TriggerType)
|
|
|
|
{
|
2018-05-22 10:18:36 +02:00
|
|
|
case TASK_EVENT_TRIGGER_ON_IDLE:
|
|
|
|
case TASK_EVENT_TRIGGER_AT_SYSTEMSTART:
|
|
|
|
case TASK_EVENT_TRIGGER_AT_LOGON:
|
|
|
|
hr = SCHED_S_EVENT_TRIGGER;
|
|
|
|
break;
|
|
|
|
|
2018-05-21 12:17:47 +02:00
|
|
|
case TASK_TIME_TRIGGER_ONCE:
|
|
|
|
st = current_st;
|
|
|
|
st.wHour = This->trigger[i].wStartHour;
|
|
|
|
st.wMinute = This->trigger[i].wStartMinute;
|
|
|
|
st.wSecond = 0;
|
|
|
|
st.wMilliseconds = 0;
|
|
|
|
SystemTimeToFileTime(&st, ¤t_ft);
|
|
|
|
if (CompareFileTime(&begin_ft, ¤t_ft) <= 0 && CompareFileTime(¤t_ft, &end_ft) < 0)
|
|
|
|
{
|
|
|
|
if (!have_best_time || CompareFileTime(¤t_ft, &best_ft) < 0)
|
|
|
|
{
|
|
|
|
best_ft = current_ft;
|
|
|
|
have_best_time = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-05-21 12:17:49 +02:00
|
|
|
case TASK_TIME_TRIGGER_DAILY:
|
|
|
|
st = current_st;
|
|
|
|
st.wHour = This->trigger[i].wStartHour;
|
|
|
|
st.wMinute = This->trigger[i].wStartMinute;
|
|
|
|
st.wSecond = 0;
|
|
|
|
st.wMilliseconds = 0;
|
|
|
|
SystemTimeToFileTime(&st, ¤t_ft);
|
|
|
|
while (CompareFileTime(¤t_ft, &end_ft) < 0)
|
|
|
|
{
|
|
|
|
if (CompareFileTime(¤t_ft, &begin_ft) >= 0)
|
|
|
|
{
|
|
|
|
if (!have_best_time || CompareFileTime(¤t_ft, &best_ft) < 0)
|
|
|
|
{
|
|
|
|
best_ft = current_ft;
|
|
|
|
have_best_time = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
filetime_add_days(¤t_ft, This->trigger[i].Type.Daily.DaysInterval);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-05-22 10:18:44 +02:00
|
|
|
case TASK_TIME_TRIGGER_WEEKLY:
|
|
|
|
if (!This->trigger[i].Type.Weekly.rgfDaysOfTheWeek)
|
|
|
|
break; /* avoid infinite loop */
|
|
|
|
|
|
|
|
st = current_st;
|
|
|
|
st.wHour = This->trigger[i].wStartHour;
|
|
|
|
st.wMinute = This->trigger[i].wStartMinute;
|
|
|
|
st.wSecond = 0;
|
|
|
|
st.wMilliseconds = 0;
|
|
|
|
SystemTimeToFileTime(&st, ¤t_ft);
|
|
|
|
while (CompareFileTime(¤t_ft, &end_ft) < 0)
|
|
|
|
{
|
|
|
|
FileTimeToSystemTime(¤t_ft, &st);
|
|
|
|
|
|
|
|
if (CompareFileTime(¤t_ft, &begin_ft) >= 0)
|
|
|
|
{
|
|
|
|
if (This->trigger[i].Type.Weekly.rgfDaysOfTheWeek & (1 << st.wDayOfWeek))
|
|
|
|
{
|
|
|
|
if (!have_best_time || CompareFileTime(¤t_ft, &best_ft) < 0)
|
|
|
|
{
|
|
|
|
best_ft = current_ft;
|
|
|
|
have_best_time = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 09:47:55 +02:00
|
|
|
if (st.wDayOfWeek == 0 && This->trigger[i].Type.Weekly.WeeksInterval > 1) /* Sunday, goto next week */
|
2018-05-22 10:18:44 +02:00
|
|
|
filetime_add_weeks(¤t_ft, This->trigger[i].Type.Weekly.WeeksInterval - 1);
|
|
|
|
else /* check next weekday */
|
|
|
|
filetime_add_days(¤t_ft, 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-05-21 12:17:47 +02:00
|
|
|
default:
|
|
|
|
FIXME("trigger type %u is not handled\n", This->trigger[i].TriggerType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (have_best_time)
|
|
|
|
{
|
|
|
|
FileTimeToSystemTime(&best_ft, rt);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2018-04-26 11:17:31 +02:00
|
|
|
|
2018-05-21 12:17:47 +02:00
|
|
|
memset(rt, 0, sizeof(*rt));
|
2018-05-22 10:18:36 +02:00
|
|
|
return hr;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITask_SetIdleWait(
|
|
|
|
ITask* iface,
|
|
|
|
WORD wIdleMinutes,
|
|
|
|
WORD wDeadlineMinutes)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %d, %d): stub\n", iface, wIdleMinutes, wDeadlineMinutes);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-04-20 10:37:18 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetIdleWait(ITask *iface, WORD *idle_minutes, WORD *deadline_minutes)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-04-20 10:37:18 +02:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %p): stub\n", iface, idle_minutes, deadline_minutes);
|
|
|
|
|
|
|
|
*idle_minutes = This->idle_minutes;
|
|
|
|
*deadline_minutes = This->deadline_minutes;
|
|
|
|
return S_OK;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-05-11 06:36:43 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_Run(ITask *iface)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-05-11 06:36:43 +02:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
|
|
|
|
if (This->status == SCHED_S_TASK_NOT_SCHEDULED)
|
|
|
|
return SCHED_E_TASK_NOT_READY;
|
|
|
|
|
|
|
|
This->flags |= 0x04000000;
|
|
|
|
return IPersistFile_Save(&This->IPersistFile_iface, NULL, FALSE);
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-05-11 06:36:45 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_Terminate(ITask *iface)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-05-11 06:36:45 +02:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
|
|
|
|
if (!This->instance_count)
|
|
|
|
return SCHED_E_TASK_NOT_RUNNING;
|
|
|
|
|
|
|
|
This->flags |= 0x08000000;
|
|
|
|
return IPersistFile_Save(&This->IPersistFile_iface, NULL, FALSE);
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITask_EditWorkItem(
|
|
|
|
ITask* iface,
|
|
|
|
HWND hParent,
|
|
|
|
DWORD dwReserved)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p, %d): stub\n", iface, hParent, dwReserved);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-04-20 10:37:27 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetMostRecentRunTime(ITask *iface, SYSTEMTIME *st)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-05-31 06:20:14 +02:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", iface, st);
|
|
|
|
|
|
|
|
if (This->status == SCHED_S_TASK_NOT_SCHEDULED)
|
|
|
|
{
|
|
|
|
memset(st, 0, sizeof(*st));
|
|
|
|
return SCHED_S_TASK_HAS_NOT_RUN;
|
|
|
|
}
|
2018-04-20 10:37:27 +02:00
|
|
|
|
2018-05-31 06:20:14 +02:00
|
|
|
*st = This->last_runtime;
|
|
|
|
return S_OK;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-04-20 10:37:08 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetStatus(ITask *iface, HRESULT *status)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-04-20 10:37:08 +02:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", iface, status);
|
|
|
|
|
2018-05-11 06:36:36 +02:00
|
|
|
*status = This->instance_count ? SCHED_S_TASK_RUNNING : This->status;
|
2018-04-20 10:37:08 +02:00
|
|
|
return S_OK;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-04-20 10:37:24 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetExitCode(ITask *iface, DWORD *exit_code)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-05-15 10:26:52 +02:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
2018-04-20 10:37:24 +02:00
|
|
|
|
2018-05-15 10:26:52 +02:00
|
|
|
TRACE("(%p, %p)\n", iface, exit_code);
|
|
|
|
|
|
|
|
*exit_code = This->exit_code;
|
|
|
|
return SCHED_S_TASK_HAS_NOT_RUN; /* FIXME */
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-03-30 11:00:05 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_SetComment(ITask *iface, LPCWSTR comment)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2011-01-24 00:17:58 +01:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
2018-04-02 07:27:07 +02:00
|
|
|
IRegistrationInfo *info;
|
|
|
|
HRESULT hr;
|
2008-08-21 22:05:43 +02:00
|
|
|
|
2018-03-30 11:00:05 +02:00
|
|
|
TRACE("(%p, %s)\n", iface, debugstr_w(comment));
|
2008-08-21 22:05:43 +02:00
|
|
|
|
2018-03-30 11:00:05 +02:00
|
|
|
if (!comment || !comment[0])
|
|
|
|
comment = NULL;
|
2008-08-21 22:05:43 +02:00
|
|
|
|
2018-04-02 07:27:07 +02:00
|
|
|
hr = ITaskDefinition_get_RegistrationInfo(This->task, &info);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = IRegistrationInfo_put_Description(info, (BSTR)comment);
|
|
|
|
IRegistrationInfo_Release(info);
|
2018-04-26 07:46:52 +02:00
|
|
|
This->is_dirty = TRUE;
|
2018-04-02 07:27:07 +02:00
|
|
|
}
|
|
|
|
return hr;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-03-30 11:00:05 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetComment(ITask *iface, LPWSTR *comment)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2011-01-24 00:17:58 +01:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
2018-04-02 07:27:07 +02:00
|
|
|
IRegistrationInfo *info;
|
2018-03-30 11:00:05 +02:00
|
|
|
HRESULT hr;
|
2018-04-02 07:27:07 +02:00
|
|
|
BSTR description;
|
2018-03-30 11:00:05 +02:00
|
|
|
DWORD len;
|
2008-08-21 22:05:43 +02:00
|
|
|
|
2018-03-30 11:00:05 +02:00
|
|
|
TRACE("(%p, %p)\n", iface, comment);
|
2008-08-21 22:05:43 +02:00
|
|
|
|
2018-04-02 07:27:07 +02:00
|
|
|
hr = ITaskDefinition_get_RegistrationInfo(This->task, &info);
|
2018-03-30 11:00:05 +02:00
|
|
|
if (hr != S_OK) return hr;
|
2008-08-21 22:05:43 +02:00
|
|
|
|
2018-04-02 07:27:07 +02:00
|
|
|
hr = IRegistrationInfo_get_Description(info, &description);
|
|
|
|
if (hr == S_OK)
|
2018-03-30 11:00:05 +02:00
|
|
|
{
|
2018-04-02 07:27:07 +02:00
|
|
|
len = description ? lstrlenW(description) + 1 : 1;
|
|
|
|
*comment = CoTaskMemAlloc(len * sizeof(WCHAR));
|
|
|
|
if (*comment)
|
|
|
|
{
|
|
|
|
if (!description)
|
|
|
|
*comment[0] = 0;
|
|
|
|
else
|
|
|
|
lstrcpyW(*comment, description);
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
2018-03-30 11:00:05 +02:00
|
|
|
else
|
2018-04-02 07:27:07 +02:00
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
SysFreeString(description);
|
2018-03-30 11:00:05 +02:00
|
|
|
}
|
2008-08-21 22:05:43 +02:00
|
|
|
|
2018-04-02 07:27:07 +02:00
|
|
|
IRegistrationInfo_Release(info);
|
2018-03-30 11:00:05 +02:00
|
|
|
return hr;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-04-02 07:27:10 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_SetCreator(ITask *iface, LPCWSTR creator)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-04-02 07:27:10 +02:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
|
|
|
IRegistrationInfo *info;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p, %s)\n", iface, debugstr_w(creator));
|
|
|
|
|
|
|
|
if (!creator || !creator[0])
|
|
|
|
creator = NULL;
|
|
|
|
|
|
|
|
hr = ITaskDefinition_get_RegistrationInfo(This->task, &info);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = IRegistrationInfo_put_Author(info, (BSTR)creator);
|
|
|
|
IRegistrationInfo_Release(info);
|
2018-04-26 07:46:52 +02:00
|
|
|
This->is_dirty = TRUE;
|
2018-04-02 07:27:10 +02:00
|
|
|
}
|
|
|
|
return hr;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-04-02 07:27:10 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetCreator(ITask *iface, LPWSTR *creator)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-04-02 07:27:10 +02:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
|
|
|
IRegistrationInfo *info;
|
|
|
|
HRESULT hr;
|
|
|
|
BSTR author;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", iface, creator);
|
|
|
|
|
|
|
|
hr = ITaskDefinition_get_RegistrationInfo(This->task, &info);
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
|
|
|
hr = IRegistrationInfo_get_Author(info, &author);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
len = author ? lstrlenW(author) + 1 : 1;
|
|
|
|
*creator = CoTaskMemAlloc(len * sizeof(WCHAR));
|
|
|
|
if (*creator)
|
|
|
|
{
|
|
|
|
if (!author)
|
|
|
|
*creator[0] = 0;
|
|
|
|
else
|
|
|
|
lstrcpyW(*creator, author);
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
SysFreeString(author);
|
|
|
|
}
|
|
|
|
|
|
|
|
IRegistrationInfo_Release(info);
|
|
|
|
return hr;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITask_SetWorkItemData(
|
|
|
|
ITask* iface,
|
|
|
|
WORD cBytes,
|
|
|
|
BYTE rgbData[])
|
|
|
|
{
|
|
|
|
FIXME("(%p, %d, %p): stub\n", iface, cBytes, rgbData);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetWorkItemData(
|
|
|
|
ITask* iface,
|
|
|
|
WORD *pcBytes,
|
|
|
|
BYTE **ppBytes)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p, %p): stub\n", iface, pcBytes, ppBytes);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITask_SetErrorRetryCount(
|
|
|
|
ITask* iface,
|
|
|
|
WORD wRetryCount)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %d): stub\n", iface, wRetryCount);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-04-20 10:37:12 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetErrorRetryCount(ITask *iface, WORD *count)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-04-20 10:37:12 +02:00
|
|
|
TRACE("(%p, %p)\n", iface, count);
|
2008-08-04 20:43:21 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITask_SetErrorRetryInterval(
|
|
|
|
ITask* iface,
|
|
|
|
WORD wRetryInterval)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %d): stub\n", iface, wRetryInterval);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-04-20 10:37:15 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetErrorRetryInterval(ITask *iface, WORD *interval)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-04-20 10:37:15 +02:00
|
|
|
TRACE("(%p, %p)\n", iface, interval);
|
2008-08-04 20:43:21 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-05-14 09:49:12 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_SetFlags(ITask *iface, DWORD flags)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-05-14 09:49:12 +02:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
|
|
|
|
|
|
|
TRACE("(%p, 0x%08x)\n", iface, flags);
|
|
|
|
This->flags &= 0xffff8000;
|
|
|
|
This->flags |= flags & 0x7fff;
|
|
|
|
This->is_dirty = TRUE;
|
2018-04-25 05:34:42 +02:00
|
|
|
return S_OK;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-03-30 10:58:39 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetFlags(ITask *iface, DWORD *flags)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-05-11 06:36:34 +02:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", iface, flags);
|
|
|
|
*flags = LOWORD(This->flags);
|
2018-03-30 10:58:39 +02:00
|
|
|
return S_OK;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITask_SetAccountInformation(
|
|
|
|
ITask* iface,
|
|
|
|
LPCWSTR pwszAccountName,
|
|
|
|
LPCWSTR pwszPassword)
|
|
|
|
{
|
2008-08-21 22:07:00 +02:00
|
|
|
DWORD n;
|
2011-01-24 00:17:58 +01:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
2008-08-21 22:07:00 +02:00
|
|
|
LPWSTR tmp_account_name;
|
|
|
|
|
|
|
|
TRACE("(%p, %s, %s): partial stub\n", iface, debugstr_w(pwszAccountName),
|
2008-08-04 20:43:21 +02:00
|
|
|
debugstr_w(pwszPassword));
|
2008-08-21 22:07:00 +02:00
|
|
|
|
|
|
|
if (pwszPassword)
|
|
|
|
FIXME("Partial stub ignores passwords\n");
|
|
|
|
|
|
|
|
n = (lstrlenW(pwszAccountName) + 1);
|
2018-04-26 07:46:46 +02:00
|
|
|
tmp_account_name = heap_alloc(n * sizeof(WCHAR));
|
2008-08-21 22:07:00 +02:00
|
|
|
if (!tmp_account_name)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
lstrcpyW(tmp_account_name, pwszAccountName);
|
2018-04-26 07:46:46 +02:00
|
|
|
heap_free(This->accountName);
|
2008-08-21 22:07:00 +02:00
|
|
|
This->accountName = tmp_account_name;
|
2018-04-26 07:46:52 +02:00
|
|
|
This->is_dirty = TRUE;
|
2008-08-21 22:07:00 +02:00
|
|
|
return S_OK;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetAccountInformation(
|
|
|
|
ITask* iface,
|
|
|
|
LPWSTR *ppwszAccountName)
|
|
|
|
{
|
2008-08-21 22:07:00 +02:00
|
|
|
DWORD n;
|
2011-01-24 00:17:58 +01:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
2008-08-21 22:07:00 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p): partial stub\n", iface, ppwszAccountName);
|
|
|
|
|
|
|
|
/* This implements the WinXP behavior when accountName has not yet
|
|
|
|
* set. Win2K behaves differently, returning SCHED_E_CANNOT_OPEN_TASK */
|
|
|
|
if (!This->accountName)
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
|
|
|
|
|
|
|
|
n = (lstrlenW(This->accountName) + 1);
|
|
|
|
*ppwszAccountName = CoTaskMemAlloc(n * sizeof(WCHAR));
|
|
|
|
if (!*ppwszAccountName)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
lstrcpyW(*ppwszAccountName, This->accountName);
|
|
|
|
return S_OK;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-03-30 10:59:47 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_SetApplicationName(ITask *iface, LPCWSTR appname)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2011-01-24 00:17:58 +01:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
2018-03-30 10:59:47 +02:00
|
|
|
DWORD len;
|
2018-04-26 07:46:52 +02:00
|
|
|
HRESULT hr;
|
2008-08-21 10:09:18 +02:00
|
|
|
|
2018-03-30 10:59:47 +02:00
|
|
|
TRACE("(%p, %s)\n", iface, debugstr_w(appname));
|
2008-08-21 10:09:18 +02:00
|
|
|
|
|
|
|
/* Empty application name */
|
2018-03-30 10:59:47 +02:00
|
|
|
if (!appname || !appname[0])
|
|
|
|
return IExecAction_put_Path(This->action, NULL);
|
2008-08-21 10:09:18 +02:00
|
|
|
|
|
|
|
/* Attempt to set pwszApplicationName to a path resolved application name */
|
2018-03-30 10:59:47 +02:00
|
|
|
len = SearchPathW(NULL, appname, NULL, 0, NULL, NULL);
|
|
|
|
if (len)
|
2008-08-21 10:09:18 +02:00
|
|
|
{
|
2018-03-30 10:59:47 +02:00
|
|
|
LPWSTR tmp_name;
|
|
|
|
|
2018-04-26 07:46:46 +02:00
|
|
|
tmp_name = heap_alloc(len * sizeof(WCHAR));
|
2008-08-21 10:09:18 +02:00
|
|
|
if (!tmp_name)
|
|
|
|
return E_OUTOFMEMORY;
|
2018-03-30 10:59:47 +02:00
|
|
|
len = SearchPathW(NULL, appname, NULL, len, tmp_name, NULL);
|
|
|
|
if (len)
|
2018-04-26 07:46:52 +02:00
|
|
|
{
|
2018-03-30 10:59:47 +02:00
|
|
|
hr = IExecAction_put_Path(This->action, tmp_name);
|
2018-04-26 07:46:52 +02:00
|
|
|
if (hr == S_OK) This->is_dirty = TRUE;
|
|
|
|
}
|
2008-08-21 10:09:18 +02:00
|
|
|
else
|
2018-03-30 10:59:47 +02:00
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
|
2018-04-26 07:46:46 +02:00
|
|
|
heap_free(tmp_name);
|
2018-03-30 10:59:47 +02:00
|
|
|
return hr;
|
2008-08-21 10:09:18 +02:00
|
|
|
}
|
|
|
|
|
2018-03-30 10:59:47 +02:00
|
|
|
/* If unable to path resolve name, simply set to appname */
|
2018-04-26 07:46:52 +02:00
|
|
|
hr = IExecAction_put_Path(This->action, (BSTR)appname);
|
|
|
|
if (hr == S_OK) This->is_dirty = TRUE;
|
|
|
|
return hr;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-03-30 10:59:47 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetApplicationName(ITask *iface, LPWSTR *appname)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2011-01-24 00:17:58 +01:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
2018-03-30 10:59:47 +02:00
|
|
|
HRESULT hr;
|
|
|
|
BSTR path;
|
|
|
|
DWORD len;
|
2008-08-21 10:09:18 +02:00
|
|
|
|
2018-03-30 10:59:47 +02:00
|
|
|
TRACE("(%p, %p)\n", iface, appname);
|
2008-08-21 10:09:18 +02:00
|
|
|
|
2018-03-30 10:59:47 +02:00
|
|
|
hr = IExecAction_get_Path(This->action, &path);
|
|
|
|
if (hr != S_OK) return hr;
|
2008-08-21 10:09:18 +02:00
|
|
|
|
2018-03-30 10:59:47 +02:00
|
|
|
len = path ? lstrlenW(path) + 1 : 1;
|
|
|
|
*appname = CoTaskMemAlloc(len * sizeof(WCHAR));
|
|
|
|
if (*appname)
|
|
|
|
{
|
|
|
|
if (!path)
|
|
|
|
*appname[0] = 0;
|
|
|
|
else
|
|
|
|
lstrcpyW(*appname, path);
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
2008-08-21 10:09:18 +02:00
|
|
|
else
|
2018-03-30 10:59:47 +02:00
|
|
|
hr = E_OUTOFMEMORY;
|
2008-08-21 10:09:18 +02:00
|
|
|
|
2018-03-30 10:59:47 +02:00
|
|
|
SysFreeString(path);
|
|
|
|
return hr;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-03-30 10:59:57 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_SetParameters(ITask *iface, LPCWSTR params)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2011-01-24 00:17:58 +01:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
2018-04-26 07:46:52 +02:00
|
|
|
HRESULT hr;
|
2008-08-21 22:05:07 +02:00
|
|
|
|
2018-03-30 10:59:57 +02:00
|
|
|
TRACE("(%p, %s)\n", iface, debugstr_w(params));
|
2008-08-21 22:05:07 +02:00
|
|
|
|
|
|
|
/* Empty parameter list */
|
2018-03-30 10:59:57 +02:00
|
|
|
if (!params || !params[0])
|
|
|
|
params = NULL;
|
2008-08-21 22:05:07 +02:00
|
|
|
|
2018-04-26 07:46:52 +02:00
|
|
|
hr = IExecAction_put_Arguments(This->action, (BSTR)params);
|
|
|
|
if (hr == S_OK) This->is_dirty = TRUE;
|
|
|
|
return hr;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-03-30 10:59:57 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetParameters(ITask *iface, LPWSTR *params)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2011-01-24 00:17:58 +01:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
2018-03-30 10:59:57 +02:00
|
|
|
HRESULT hr;
|
|
|
|
BSTR args;
|
|
|
|
DWORD len;
|
2008-08-21 22:05:07 +02:00
|
|
|
|
2018-03-30 10:59:57 +02:00
|
|
|
TRACE("(%p, %p)\n", iface, params);
|
2008-08-21 22:05:07 +02:00
|
|
|
|
2018-03-30 10:59:57 +02:00
|
|
|
hr = IExecAction_get_Arguments(This->action, &args);
|
|
|
|
if (hr != S_OK) return hr;
|
2008-08-21 22:05:07 +02:00
|
|
|
|
2018-03-30 10:59:57 +02:00
|
|
|
len = args ? lstrlenW(args) + 1 : 1;
|
|
|
|
*params = CoTaskMemAlloc(len * sizeof(WCHAR));
|
|
|
|
if (*params)
|
|
|
|
{
|
|
|
|
if (!args)
|
|
|
|
*params[0] = 0;
|
|
|
|
else
|
|
|
|
lstrcpyW(*params, args);
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
2008-08-21 22:05:07 +02:00
|
|
|
else
|
2018-03-30 10:59:57 +02:00
|
|
|
hr = E_OUTOFMEMORY;
|
2008-08-21 22:05:07 +02:00
|
|
|
|
2018-03-30 10:59:57 +02:00
|
|
|
SysFreeString(args);
|
|
|
|
return hr;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-03-30 11:00:02 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_SetWorkingDirectory(ITask * iface, LPCWSTR workdir)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-03-30 11:00:02 +02:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
2018-04-26 07:46:52 +02:00
|
|
|
HRESULT hr;
|
2018-03-30 11:00:02 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %s)\n", iface, debugstr_w(workdir));
|
|
|
|
|
|
|
|
if (!workdir || !workdir[0])
|
|
|
|
workdir = NULL;
|
|
|
|
|
2018-04-26 07:46:52 +02:00
|
|
|
hr = IExecAction_put_WorkingDirectory(This->action, (BSTR)workdir);
|
|
|
|
if (hr == S_OK) This->is_dirty = TRUE;
|
|
|
|
return hr;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-03-30 11:00:02 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetWorkingDirectory(ITask *iface, LPWSTR *workdir)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-03-30 11:00:02 +02:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
BSTR dir;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", iface, workdir);
|
|
|
|
|
|
|
|
hr = IExecAction_get_WorkingDirectory(This->action, &dir);
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
|
|
|
len = dir ? lstrlenW(dir) + 1 : 1;
|
|
|
|
*workdir = CoTaskMemAlloc(len * sizeof(WCHAR));
|
|
|
|
if (*workdir)
|
|
|
|
{
|
|
|
|
if (!dir)
|
|
|
|
*workdir[0] = 0;
|
|
|
|
else
|
|
|
|
lstrcpyW(*workdir, dir);
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
SysFreeString(dir);
|
|
|
|
return hr;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITask_SetPriority(
|
|
|
|
ITask* iface,
|
|
|
|
DWORD dwPriority)
|
|
|
|
{
|
|
|
|
FIXME("(%p, 0x%08x): stub\n", iface, dwPriority);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-04-20 10:37:21 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetPriority(ITask *iface, DWORD *priority)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-04-20 10:37:21 +02:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", iface, priority);
|
|
|
|
|
|
|
|
*priority = This->priority;
|
|
|
|
return S_OK;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITask_SetTaskFlags(
|
|
|
|
ITask* iface,
|
|
|
|
DWORD dwFlags)
|
|
|
|
{
|
|
|
|
FIXME("(%p, 0x%08x): stub\n", iface, dwFlags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-03-30 10:58:39 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetTaskFlags(ITask *iface, DWORD *flags)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-03-30 10:58:39 +02:00
|
|
|
FIXME("(%p, %p): stub\n", iface, flags);
|
|
|
|
*flags = 0;
|
|
|
|
return S_OK;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITask_SetMaxRunTime(
|
|
|
|
ITask* iface,
|
|
|
|
DWORD dwMaxRunTime)
|
|
|
|
{
|
2011-01-24 00:17:58 +01:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
2008-08-21 22:06:19 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %d)\n", iface, dwMaxRunTime);
|
|
|
|
|
|
|
|
This->maxRunTime = dwMaxRunTime;
|
2018-04-26 07:46:52 +02:00
|
|
|
This->is_dirty = TRUE;
|
2008-08-21 22:06:19 +02:00
|
|
|
return S_OK;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITask_GetMaxRunTime(
|
|
|
|
ITask* iface,
|
|
|
|
DWORD *pdwMaxRunTime)
|
|
|
|
{
|
2011-01-24 00:17:58 +01:00
|
|
|
TaskImpl *This = impl_from_ITask(iface);
|
2008-08-21 22:06:19 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", iface, pdwMaxRunTime);
|
|
|
|
|
|
|
|
*pdwMaxRunTime = This->maxRunTime;
|
|
|
|
return S_OK;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_IPersistFile_QueryInterface(
|
|
|
|
IPersistFile* iface,
|
|
|
|
REFIID riid,
|
|
|
|
void **ppvObject)
|
|
|
|
{
|
2008-08-21 17:54:01 +02:00
|
|
|
TaskImpl *This = impl_from_IPersistFile(iface);
|
|
|
|
TRACE("(%p, %s, %p)\n", iface, debugstr_guid(riid), ppvObject);
|
2011-01-24 00:17:58 +01:00
|
|
|
return ITask_QueryInterface(&This->ITask_iface, riid, ppvObject);
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MSTASK_IPersistFile_AddRef(
|
|
|
|
IPersistFile* iface)
|
|
|
|
{
|
2008-08-21 17:54:01 +02:00
|
|
|
TaskImpl *This = impl_from_IPersistFile(iface);
|
2018-04-26 07:46:49 +02:00
|
|
|
return ITask_AddRef(&This->ITask_iface);
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MSTASK_IPersistFile_Release(
|
|
|
|
IPersistFile* iface)
|
|
|
|
{
|
2008-08-21 17:54:01 +02:00
|
|
|
TaskImpl *This = impl_from_IPersistFile(iface);
|
2018-04-26 07:46:49 +02:00
|
|
|
return ITask_Release(&This->ITask_iface);
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-04-20 10:37:04 +02:00
|
|
|
static HRESULT WINAPI MSTASK_IPersistFile_GetClassID(IPersistFile *iface, CLSID *clsid)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-04-20 10:37:04 +02:00
|
|
|
TRACE("(%p, %p)\n", iface, clsid);
|
|
|
|
|
|
|
|
*clsid = CLSID_CTask;
|
|
|
|
return S_OK;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-04-26 07:46:52 +02:00
|
|
|
static HRESULT WINAPI MSTASK_IPersistFile_IsDirty(IPersistFile *iface)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-04-26 07:46:52 +02:00
|
|
|
TaskImpl *This = impl_from_IPersistFile(iface);
|
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
return This->is_dirty ? S_OK : S_FALSE;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-04-25 05:34:38 +02:00
|
|
|
static DWORD load_unicode_strings(ITask *task, BYTE *data, DWORD limit)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-04-25 05:34:38 +02:00
|
|
|
DWORD i, data_size = 0;
|
|
|
|
USHORT len;
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
if (limit < sizeof(USHORT))
|
|
|
|
{
|
|
|
|
TRACE("invalid string %u offset\n", i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = *(USHORT *)data;
|
|
|
|
data += sizeof(USHORT);
|
|
|
|
data_size += sizeof(USHORT);
|
|
|
|
limit -= sizeof(USHORT);
|
|
|
|
if (limit < len * sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
TRACE("invalid string %u size\n", i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("string %u: %s\n", i, wine_dbgstr_wn((const WCHAR *)data, len));
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
ITask_SetApplicationName(task, (const WCHAR *)data);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
ITask_SetParameters(task, (const WCHAR *)data);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ITask_SetWorkingDirectory(task, (const WCHAR *)data);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ITask_SetCreator(task, (const WCHAR *)data);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
ITask_SetComment(task, (const WCHAR *)data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
data += len * sizeof(WCHAR);
|
|
|
|
data_size += len * sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return data_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT load_job_data(TaskImpl *This, BYTE *data, DWORD size)
|
|
|
|
{
|
|
|
|
ITask *task = &This->ITask_iface;
|
|
|
|
HRESULT hr;
|
|
|
|
const FIXDLEN_DATA *fixed;
|
|
|
|
const SYSTEMTIME *st;
|
|
|
|
DWORD unicode_strings_size, data_size, triggers_size;
|
2018-05-11 06:36:31 +02:00
|
|
|
USHORT trigger_count, i;
|
2018-04-25 05:34:38 +02:00
|
|
|
const USHORT *signature;
|
|
|
|
TASK_TRIGGER *task_trigger;
|
|
|
|
|
|
|
|
if (size < sizeof(*fixed))
|
|
|
|
{
|
|
|
|
TRACE("no space for FIXDLEN_DATA\n");
|
|
|
|
return SCHED_E_INVALID_TASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
fixed = (const FIXDLEN_DATA *)data;
|
|
|
|
|
|
|
|
TRACE("product_version %04x\n", fixed->product_version);
|
|
|
|
TRACE("file_version %04x\n", fixed->file_version);
|
|
|
|
TRACE("uuid %s\n", wine_dbgstr_guid(&fixed->uuid));
|
|
|
|
|
|
|
|
if (fixed->file_version != 0x0001)
|
|
|
|
return SCHED_E_INVALID_TASK;
|
|
|
|
|
2018-05-24 10:29:26 +02:00
|
|
|
This->uuid = fixed->uuid;
|
|
|
|
|
2018-04-25 05:34:38 +02:00
|
|
|
TRACE("name_size_offset %04x\n", fixed->name_size_offset);
|
|
|
|
TRACE("trigger_offset %04x\n", fixed->trigger_offset);
|
|
|
|
TRACE("error_retry_count %u\n", fixed->error_retry_count);
|
|
|
|
TRACE("error_retry_interval %u\n", fixed->error_retry_interval);
|
|
|
|
TRACE("idle_deadline %u\n", fixed->idle_deadline);
|
|
|
|
This->deadline_minutes = fixed->idle_deadline;
|
|
|
|
TRACE("idle_wait %u\n", fixed->idle_wait);
|
|
|
|
This->idle_minutes = fixed->idle_wait;
|
|
|
|
TRACE("priority %08x\n", fixed->priority);
|
|
|
|
This->priority = fixed->priority;
|
|
|
|
TRACE("maximum_runtime %u\n", fixed->maximum_runtime);
|
|
|
|
This->maxRunTime = fixed->maximum_runtime;
|
|
|
|
TRACE("exit_code %#x\n", fixed->exit_code);
|
2018-05-15 10:26:52 +02:00
|
|
|
This->exit_code = fixed->exit_code;
|
2018-04-25 05:34:38 +02:00
|
|
|
TRACE("status %08x\n", fixed->status);
|
2018-05-11 06:36:31 +02:00
|
|
|
This->status = fixed->status;
|
2018-04-25 05:34:38 +02:00
|
|
|
TRACE("flags %08x\n", fixed->flags);
|
2018-05-11 06:36:31 +02:00
|
|
|
This->flags = fixed->flags;
|
2018-05-31 06:20:14 +02:00
|
|
|
This->last_runtime = fixed->last_runtime;
|
2018-04-25 05:34:38 +02:00
|
|
|
st = &fixed->last_runtime;
|
2018-05-31 06:20:14 +02:00
|
|
|
TRACE("last_runtime %u/%u/%u wday %u %u:%02u:%02u.%03u\n",
|
2018-04-25 05:34:38 +02:00
|
|
|
st->wDay, st->wMonth, st->wYear, st->wDayOfWeek,
|
|
|
|
st->wHour, st->wMinute, st->wSecond, st->wMilliseconds);
|
|
|
|
|
|
|
|
/* Instance Count */
|
|
|
|
if (size < sizeof(*fixed) + sizeof(USHORT))
|
|
|
|
{
|
|
|
|
TRACE("no space for instance count\n");
|
|
|
|
return SCHED_E_INVALID_TASK;
|
|
|
|
}
|
|
|
|
|
2018-05-11 06:36:31 +02:00
|
|
|
This->instance_count = *(const USHORT *)(data + sizeof(*fixed));
|
|
|
|
TRACE("instance count %u\n", This->instance_count);
|
2018-04-25 05:34:38 +02:00
|
|
|
|
|
|
|
if (fixed->name_size_offset + sizeof(USHORT) < size)
|
|
|
|
unicode_strings_size = load_unicode_strings(task, data + fixed->name_size_offset, size - fixed->name_size_offset);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("invalid name_size_offset\n");
|
|
|
|
return SCHED_E_INVALID_TASK;
|
|
|
|
}
|
|
|
|
TRACE("unicode strings end at %#x\n", fixed->name_size_offset + unicode_strings_size);
|
|
|
|
|
|
|
|
if (size < fixed->trigger_offset + sizeof(USHORT))
|
|
|
|
{
|
|
|
|
TRACE("no space for triggers count\n");
|
|
|
|
return SCHED_E_INVALID_TASK;
|
|
|
|
}
|
|
|
|
trigger_count = *(const USHORT *)(data + fixed->trigger_offset);
|
|
|
|
TRACE("trigger_count %u\n", trigger_count);
|
|
|
|
triggers_size = size - fixed->trigger_offset - sizeof(USHORT);
|
|
|
|
TRACE("triggers_size %u\n", triggers_size);
|
|
|
|
task_trigger = (TASK_TRIGGER *)(data + fixed->trigger_offset + sizeof(USHORT));
|
|
|
|
|
|
|
|
data += fixed->name_size_offset + unicode_strings_size;
|
|
|
|
size -= fixed->name_size_offset + unicode_strings_size;
|
|
|
|
|
|
|
|
/* User Data */
|
|
|
|
if (size < sizeof(USHORT))
|
|
|
|
{
|
|
|
|
TRACE("no space for user data size\n");
|
|
|
|
return SCHED_E_INVALID_TASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
data_size = *(const USHORT *)data;
|
|
|
|
if (size < sizeof(USHORT) + data_size)
|
|
|
|
{
|
|
|
|
TRACE("no space for user data\n");
|
|
|
|
return SCHED_E_INVALID_TASK;
|
|
|
|
}
|
|
|
|
TRACE("User Data size %#x\n", data_size);
|
|
|
|
ITask_SetWorkItemData(task, data_size, data + sizeof(USHORT));
|
|
|
|
|
|
|
|
size -= sizeof(USHORT) + data_size;
|
|
|
|
data += sizeof(USHORT) + data_size;
|
|
|
|
|
|
|
|
/* Reserved Data */
|
|
|
|
if (size < sizeof(USHORT))
|
|
|
|
{
|
|
|
|
TRACE("no space for reserved data size\n");
|
|
|
|
return SCHED_E_INVALID_TASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
data_size = *(const USHORT *)data;
|
|
|
|
if (size < sizeof(USHORT) + data_size)
|
|
|
|
{
|
|
|
|
TRACE("no space for reserved data\n");
|
|
|
|
return SCHED_E_INVALID_TASK;
|
|
|
|
}
|
|
|
|
TRACE("Reserved Data size %#x\n", data_size);
|
|
|
|
|
|
|
|
size -= sizeof(USHORT) + data_size;
|
|
|
|
data += sizeof(USHORT) + data_size;
|
|
|
|
|
|
|
|
/* Trigger Data */
|
|
|
|
TRACE("trigger_offset %04x, triggers end at %04x\n", fixed->trigger_offset,
|
|
|
|
(DWORD)(fixed->trigger_offset + sizeof(USHORT) + trigger_count * sizeof(TASK_TRIGGER)));
|
|
|
|
|
|
|
|
task_trigger = (TASK_TRIGGER *)(data + sizeof(USHORT));
|
|
|
|
|
2018-04-26 11:17:33 +02:00
|
|
|
if (trigger_count * sizeof(TASK_TRIGGER) > triggers_size)
|
2018-04-25 05:34:38 +02:00
|
|
|
{
|
|
|
|
TRACE("no space for triggers data\n");
|
|
|
|
return SCHED_E_INVALID_TASK;
|
|
|
|
}
|
|
|
|
|
2018-04-26 11:17:33 +02:00
|
|
|
This->trigger_count = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < trigger_count; i++)
|
2018-04-25 05:34:38 +02:00
|
|
|
{
|
|
|
|
ITaskTrigger *trigger;
|
|
|
|
WORD idx;
|
|
|
|
|
|
|
|
hr = ITask_CreateTrigger(task, &idx, &trigger);
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
|
|
|
hr = ITaskTrigger_SetTrigger(trigger, &task_trigger[i]);
|
|
|
|
ITaskTrigger_Release(trigger);
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
ITask_DeleteTrigger(task, idx);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-26 11:17:33 +02:00
|
|
|
size -= sizeof(USHORT) + trigger_count * sizeof(TASK_TRIGGER);
|
|
|
|
data += sizeof(USHORT) + trigger_count * sizeof(TASK_TRIGGER);
|
2018-04-25 05:34:38 +02:00
|
|
|
|
|
|
|
if (size < 2 * sizeof(USHORT) + 64)
|
|
|
|
{
|
|
|
|
TRACE("no space for signature\n");
|
|
|
|
return S_OK; /* signature is optional */
|
|
|
|
}
|
|
|
|
|
|
|
|
signature = (const USHORT *)data;
|
|
|
|
TRACE("signature version %04x, client version %04x\n", signature[0], signature[1]);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_IPersistFile_Load(IPersistFile *iface, LPCOLESTR file_name, DWORD mode)
|
|
|
|
{
|
|
|
|
TaskImpl *This = impl_from_IPersistFile(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
HANDLE file, mapping;
|
|
|
|
DWORD access, sharing, size;
|
|
|
|
void *data;
|
|
|
|
|
|
|
|
TRACE("(%p, %s, 0x%08x)\n", iface, debugstr_w(file_name), mode);
|
|
|
|
|
|
|
|
switch (mode & 0x000f)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case STGM_READ:
|
|
|
|
access = GENERIC_READ;
|
|
|
|
break;
|
|
|
|
case STGM_WRITE:
|
|
|
|
case STGM_READWRITE:
|
|
|
|
access = GENERIC_READ | GENERIC_WRITE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mode & 0x00f0)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case STGM_SHARE_DENY_NONE:
|
|
|
|
sharing = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
|
|
|
break;
|
|
|
|
case STGM_SHARE_DENY_READ:
|
|
|
|
sharing = FILE_SHARE_WRITE;
|
|
|
|
break;
|
|
|
|
case STGM_SHARE_DENY_WRITE:
|
|
|
|
sharing = FILE_SHARE_READ;
|
|
|
|
break;
|
|
|
|
case STGM_SHARE_EXCLUSIVE:
|
|
|
|
sharing = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
file = CreateFileW(file_name, access, sharing, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
if (file == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
TRACE("Failed to open %s, error %u\n", debugstr_w(file_name), GetLastError());
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
size = GetFileSize(file, NULL);
|
|
|
|
|
|
|
|
mapping = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, 0);
|
|
|
|
if (!mapping)
|
|
|
|
{
|
|
|
|
TRACE("Failed to create file mapping %s, error %u\n", debugstr_w(file_name), GetLastError());
|
|
|
|
CloseHandle(file);
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
data = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0);
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
hr = load_job_data(This, data, size);
|
2018-04-26 07:46:52 +02:00
|
|
|
if (hr == S_OK) This->is_dirty = FALSE;
|
2018-04-25 05:34:38 +02:00
|
|
|
UnmapViewOfFile(data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
|
|
|
|
CloseHandle(mapping);
|
|
|
|
CloseHandle(file);
|
|
|
|
|
|
|
|
return hr;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-04-20 10:37:31 +02:00
|
|
|
static BOOL write_signature(HANDLE hfile)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-04-20 10:37:31 +02:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
USHORT SignatureVersion;
|
|
|
|
USHORT ClientVersion;
|
|
|
|
BYTE md5[64];
|
|
|
|
} signature;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
signature.SignatureVersion = 0x0001;
|
|
|
|
signature.ClientVersion = 0x0001;
|
|
|
|
memset(&signature.md5, 0, sizeof(signature.md5));
|
|
|
|
|
|
|
|
return WriteFile(hfile, &signature, sizeof(signature), &size, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL write_reserved_data(HANDLE hfile)
|
|
|
|
{
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
USHORT size;
|
|
|
|
BYTE data[8];
|
|
|
|
} user = { 8, { 0xff,0x0f,0x1d,0,0,0,0,0 } };
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
return WriteFile(hfile, &user, sizeof(user), &size, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL write_user_data(HANDLE hfile, BYTE *data, WORD data_size)
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
if (!WriteFile(hfile, &data_size, sizeof(data_size), &size, NULL))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!data_size) return TRUE;
|
|
|
|
|
|
|
|
return WriteFile(hfile, data, data_size, &size, NULL);
|
|
|
|
}
|
|
|
|
|
2018-05-15 10:26:50 +02:00
|
|
|
static HRESULT write_triggers(TaskImpl *This, HANDLE hfile)
|
2018-04-20 10:37:31 +02:00
|
|
|
{
|
2018-04-24 10:13:24 +02:00
|
|
|
WORD count, i, idx = 0xffff;
|
2018-04-20 10:37:31 +02:00
|
|
|
DWORD size;
|
2018-05-15 10:26:50 +02:00
|
|
|
HRESULT hr = S_OK;
|
2018-04-24 10:13:24 +02:00
|
|
|
ITaskTrigger *trigger;
|
2018-04-20 10:37:31 +02:00
|
|
|
|
2018-05-15 10:26:50 +02:00
|
|
|
count = This->trigger_count;
|
2018-04-20 10:37:31 +02:00
|
|
|
|
2018-04-24 10:13:24 +02:00
|
|
|
/* Windows saves a .job with at least 1 trigger */
|
|
|
|
if (!count)
|
|
|
|
{
|
2018-05-15 10:26:50 +02:00
|
|
|
hr = ITask_CreateTrigger(&This->ITask_iface, &idx, &trigger);
|
2018-04-24 10:13:24 +02:00
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
ITaskTrigger_Release(trigger);
|
|
|
|
|
|
|
|
count = 1;
|
|
|
|
}
|
|
|
|
|
2018-05-15 10:26:50 +02:00
|
|
|
if (WriteFile(hfile, &count, sizeof(count), &size, NULL))
|
2018-04-20 10:37:31 +02:00
|
|
|
{
|
2018-05-15 10:26:50 +02:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (!WriteFile(hfile, &This->trigger[i], sizeof(This->trigger[0]), &size, NULL))
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-04-20 10:37:31 +02:00
|
|
|
}
|
2018-05-15 10:26:50 +02:00
|
|
|
else
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
2018-04-20 10:37:31 +02:00
|
|
|
|
2018-04-24 10:13:24 +02:00
|
|
|
if (idx != 0xffff)
|
2018-05-15 10:26:50 +02:00
|
|
|
ITask_DeleteTrigger(&This->ITask_iface, idx);
|
2018-04-24 10:13:24 +02:00
|
|
|
|
|
|
|
return hr;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
2018-04-20 10:37:31 +02:00
|
|
|
static BOOL write_unicode_string(HANDLE hfile, const WCHAR *str)
|
|
|
|
{
|
|
|
|
USHORT count;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
count = str ? (lstrlenW(str) + 1) : 0;
|
|
|
|
if (!WriteFile(hfile, &count, sizeof(count), &size, NULL))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!str) return TRUE;
|
|
|
|
|
|
|
|
count *= sizeof(WCHAR);
|
|
|
|
return WriteFile(hfile, str, count, &size, NULL);
|
|
|
|
}
|
|
|
|
|
2018-04-24 10:13:31 +02:00
|
|
|
static HRESULT WINAPI MSTASK_IPersistFile_Save(IPersistFile *iface, LPCOLESTR task_name, BOOL remember)
|
2018-04-20 10:37:31 +02:00
|
|
|
{
|
|
|
|
static WCHAR authorW[] = { 'W','i','n','e',0 };
|
|
|
|
static WCHAR commentW[] = { 'C','r','e','a','t','e','d',' ','b','y',' ','W','i','n','e',0 };
|
|
|
|
FIXDLEN_DATA fixed;
|
|
|
|
WORD word, user_data_size = 0;
|
|
|
|
HANDLE hfile;
|
2018-05-11 06:36:41 +02:00
|
|
|
DWORD size, ver, disposition, try;
|
2018-04-20 10:37:31 +02:00
|
|
|
TaskImpl *This = impl_from_IPersistFile(iface);
|
|
|
|
ITask *task = &This->ITask_iface;
|
|
|
|
LPWSTR appname = NULL, params = NULL, workdir = NULL, creator = NULL, comment = NULL;
|
|
|
|
BYTE *user_data = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2018-04-24 10:13:31 +02:00
|
|
|
TRACE("(%p, %s, %d)\n", iface, debugstr_w(task_name), remember);
|
2018-04-20 10:37:31 +02:00
|
|
|
|
2018-04-24 10:13:31 +02:00
|
|
|
disposition = task_name ? CREATE_NEW : OPEN_ALWAYS;
|
2018-04-20 10:37:31 +02:00
|
|
|
|
2018-04-24 10:13:31 +02:00
|
|
|
if (!task_name)
|
2018-04-20 10:37:31 +02:00
|
|
|
{
|
2018-04-24 10:13:31 +02:00
|
|
|
task_name = This->task_name;
|
2018-04-20 10:37:31 +02:00
|
|
|
remember = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ITask_GetComment(task, &comment);
|
|
|
|
if (!comment) comment = commentW;
|
|
|
|
ITask_GetCreator(task, &creator);
|
|
|
|
if (!creator) creator = authorW;
|
|
|
|
ITask_GetApplicationName(task, &appname);
|
|
|
|
ITask_GetParameters(task, ¶ms);
|
|
|
|
ITask_GetWorkingDirectory(task, &workdir);
|
|
|
|
ITask_GetWorkItemData(task, &user_data_size, &user_data);
|
|
|
|
|
|
|
|
ver = GetVersion();
|
|
|
|
fixed.product_version = MAKEWORD(ver >> 8, ver);
|
|
|
|
fixed.file_version = 0x0001;
|
|
|
|
fixed.name_size_offset = sizeof(fixed) + sizeof(USHORT); /* FIXDLEN_DATA + Instance Count */
|
|
|
|
fixed.trigger_offset = sizeof(fixed) + sizeof(USHORT); /* FIXDLEN_DATA + Instance Count */
|
|
|
|
fixed.trigger_offset += sizeof(USHORT); /* Application Name */
|
|
|
|
if (appname)
|
|
|
|
fixed.trigger_offset += (lstrlenW(appname) + 1) * sizeof(WCHAR);
|
|
|
|
fixed.trigger_offset += sizeof(USHORT); /* Parameters */
|
|
|
|
if (params)
|
|
|
|
fixed.trigger_offset += (lstrlenW(params) + 1) * sizeof(WCHAR);
|
|
|
|
fixed.trigger_offset += sizeof(USHORT); /* Working Directory */
|
|
|
|
if (workdir)
|
|
|
|
fixed.trigger_offset += (lstrlenW(workdir) + 1) * sizeof(WCHAR);
|
|
|
|
fixed.trigger_offset += sizeof(USHORT); /* Author */
|
|
|
|
if (creator)
|
|
|
|
fixed.trigger_offset += (lstrlenW(creator) + 1) * sizeof(WCHAR);
|
|
|
|
fixed.trigger_offset += sizeof(USHORT); /* Comment */
|
|
|
|
if (comment)
|
|
|
|
fixed.trigger_offset += (lstrlenW(comment) + 1) * sizeof(WCHAR);
|
|
|
|
fixed.trigger_offset += sizeof(USHORT) + user_data_size; /* User Data */
|
|
|
|
fixed.trigger_offset += 10; /* Reserved Data */
|
|
|
|
|
|
|
|
fixed.error_retry_count = 0;
|
|
|
|
fixed.error_retry_interval = 0;
|
|
|
|
fixed.idle_wait = This->idle_minutes;
|
|
|
|
fixed.idle_deadline = This->deadline_minutes;
|
|
|
|
fixed.priority = This->priority;
|
|
|
|
fixed.maximum_runtime = This->maxRunTime;
|
2018-05-15 10:26:52 +02:00
|
|
|
fixed.exit_code = This->exit_code;
|
2018-05-11 06:36:39 +02:00
|
|
|
if (This->status == SCHED_S_TASK_NOT_SCHEDULED && This->trigger_count)
|
|
|
|
This->status = SCHED_S_TASK_HAS_NOT_RUN;
|
|
|
|
fixed.status = This->status;
|
|
|
|
fixed.flags = This->flags;
|
2018-05-31 06:20:14 +02:00
|
|
|
fixed.last_runtime = This->last_runtime;
|
2018-04-20 10:37:31 +02:00
|
|
|
|
2018-05-11 06:36:41 +02:00
|
|
|
try = 1;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
hfile = CreateFileW(task_name, GENERIC_READ | GENERIC_WRITE, 0, NULL, disposition, 0, 0);
|
|
|
|
if (hfile != INVALID_HANDLE_VALUE) break;
|
|
|
|
|
|
|
|
if (try++ >= 3) return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
Sleep(100);
|
|
|
|
}
|
2018-04-20 10:37:31 +02:00
|
|
|
|
2018-05-24 10:29:26 +02:00
|
|
|
if (GetLastError() == ERROR_ALREADY_EXISTS)
|
|
|
|
fixed.uuid = This->uuid;
|
|
|
|
else
|
|
|
|
CoCreateGuid(&fixed.uuid);
|
|
|
|
|
2018-04-20 10:37:31 +02:00
|
|
|
if (!WriteFile(hfile, &fixed, sizeof(fixed), &size, NULL))
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2018-05-11 06:36:28 +02:00
|
|
|
/* Instance Count: don't touch it in the client */
|
|
|
|
if (SetFilePointer(hfile, sizeof(word), NULL, FILE_CURRENT) == INVALID_SET_FILE_POINTER)
|
2018-04-20 10:37:31 +02:00
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
/* Application Name */
|
|
|
|
if (!write_unicode_string(hfile, appname))
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
/* Parameters */
|
|
|
|
if (!write_unicode_string(hfile, params))
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
/* Working Directory */
|
|
|
|
if (!write_unicode_string(hfile, workdir))
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
/* Author */
|
|
|
|
if (!write_unicode_string(hfile, creator))
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
/* Comment */
|
|
|
|
if (!write_unicode_string(hfile, comment))
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* User Data */
|
|
|
|
if (!write_user_data(hfile, user_data, user_data_size))
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reserved Data */
|
|
|
|
if (!write_reserved_data(hfile))
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2018-04-24 10:13:38 +02:00
|
|
|
/* Triggers */
|
2018-05-15 10:26:50 +02:00
|
|
|
hr = write_triggers(This, hfile);
|
2018-04-24 10:13:38 +02:00
|
|
|
if (hr != S_OK)
|
2018-04-20 10:37:31 +02:00
|
|
|
goto failed;
|
|
|
|
|
|
|
|
/* Signature */
|
|
|
|
if (!write_signature(hfile))
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = S_OK;
|
2018-04-26 07:46:52 +02:00
|
|
|
This->is_dirty = FALSE;
|
2018-04-20 10:37:31 +02:00
|
|
|
|
|
|
|
failed:
|
|
|
|
CoTaskMemFree(appname);
|
|
|
|
CoTaskMemFree(params);
|
|
|
|
CoTaskMemFree(workdir);
|
|
|
|
if (creator != authorW)
|
|
|
|
CoTaskMemFree(creator);
|
|
|
|
if (comment != commentW)
|
|
|
|
CoTaskMemFree(comment);
|
|
|
|
CoTaskMemFree(user_data);
|
|
|
|
|
|
|
|
CloseHandle(hfile);
|
|
|
|
if (hr != S_OK)
|
2018-04-24 10:13:31 +02:00
|
|
|
DeleteFileW(task_name);
|
2018-04-20 10:37:31 +02:00
|
|
|
else if (remember)
|
|
|
|
{
|
2018-04-26 07:46:46 +02:00
|
|
|
heap_free(This->task_name);
|
2018-04-24 10:13:31 +02:00
|
|
|
This->task_name = heap_strdupW(task_name);
|
2018-04-20 10:37:31 +02:00
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-08-04 20:43:21 +02:00
|
|
|
static HRESULT WINAPI MSTASK_IPersistFile_SaveCompleted(
|
|
|
|
IPersistFile* iface,
|
|
|
|
LPCOLESTR pszFileName)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p): stub\n", iface, pszFileName);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-04-25 05:34:34 +02:00
|
|
|
static HRESULT WINAPI MSTASK_IPersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *file_name)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-04-25 05:34:34 +02:00
|
|
|
TaskImpl *This = impl_from_IPersistFile(iface);
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", iface, file_name);
|
|
|
|
|
|
|
|
*file_name = CoTaskMemAlloc((strlenW(This->task_name) + 1) * sizeof(WCHAR));
|
|
|
|
if (!*file_name) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
strcpyW(*file_name, This->task_name);
|
|
|
|
return S_OK;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const ITaskVtbl MSTASK_ITaskVtbl =
|
|
|
|
{
|
|
|
|
MSTASK_ITask_QueryInterface,
|
|
|
|
MSTASK_ITask_AddRef,
|
|
|
|
MSTASK_ITask_Release,
|
|
|
|
MSTASK_ITask_CreateTrigger,
|
|
|
|
MSTASK_ITask_DeleteTrigger,
|
|
|
|
MSTASK_ITask_GetTriggerCount,
|
|
|
|
MSTASK_ITask_GetTrigger,
|
|
|
|
MSTASK_ITask_GetTriggerString,
|
|
|
|
MSTASK_ITask_GetRunTimes,
|
|
|
|
MSTASK_ITask_GetNextRunTime,
|
|
|
|
MSTASK_ITask_SetIdleWait,
|
|
|
|
MSTASK_ITask_GetIdleWait,
|
|
|
|
MSTASK_ITask_Run,
|
|
|
|
MSTASK_ITask_Terminate,
|
|
|
|
MSTASK_ITask_EditWorkItem,
|
|
|
|
MSTASK_ITask_GetMostRecentRunTime,
|
|
|
|
MSTASK_ITask_GetStatus,
|
|
|
|
MSTASK_ITask_GetExitCode,
|
|
|
|
MSTASK_ITask_SetComment,
|
|
|
|
MSTASK_ITask_GetComment,
|
|
|
|
MSTASK_ITask_SetCreator,
|
|
|
|
MSTASK_ITask_GetCreator,
|
|
|
|
MSTASK_ITask_SetWorkItemData,
|
|
|
|
MSTASK_ITask_GetWorkItemData,
|
|
|
|
MSTASK_ITask_SetErrorRetryCount,
|
|
|
|
MSTASK_ITask_GetErrorRetryCount,
|
|
|
|
MSTASK_ITask_SetErrorRetryInterval,
|
|
|
|
MSTASK_ITask_GetErrorRetryInterval,
|
|
|
|
MSTASK_ITask_SetFlags,
|
|
|
|
MSTASK_ITask_GetFlags,
|
|
|
|
MSTASK_ITask_SetAccountInformation,
|
|
|
|
MSTASK_ITask_GetAccountInformation,
|
|
|
|
MSTASK_ITask_SetApplicationName,
|
|
|
|
MSTASK_ITask_GetApplicationName,
|
|
|
|
MSTASK_ITask_SetParameters,
|
|
|
|
MSTASK_ITask_GetParameters,
|
|
|
|
MSTASK_ITask_SetWorkingDirectory,
|
|
|
|
MSTASK_ITask_GetWorkingDirectory,
|
|
|
|
MSTASK_ITask_SetPriority,
|
|
|
|
MSTASK_ITask_GetPriority,
|
|
|
|
MSTASK_ITask_SetTaskFlags,
|
|
|
|
MSTASK_ITask_GetTaskFlags,
|
|
|
|
MSTASK_ITask_SetMaxRunTime,
|
|
|
|
MSTASK_ITask_GetMaxRunTime
|
|
|
|
};
|
|
|
|
|
|
|
|
static const IPersistFileVtbl MSTASK_IPersistFileVtbl =
|
|
|
|
{
|
|
|
|
MSTASK_IPersistFile_QueryInterface,
|
|
|
|
MSTASK_IPersistFile_AddRef,
|
|
|
|
MSTASK_IPersistFile_Release,
|
|
|
|
MSTASK_IPersistFile_GetClassID,
|
|
|
|
MSTASK_IPersistFile_IsDirty,
|
|
|
|
MSTASK_IPersistFile_Load,
|
|
|
|
MSTASK_IPersistFile_Save,
|
|
|
|
MSTASK_IPersistFile_SaveCompleted,
|
|
|
|
MSTASK_IPersistFile_GetCurFile
|
|
|
|
};
|
|
|
|
|
2018-04-24 10:13:31 +02:00
|
|
|
HRESULT TaskConstructor(ITaskService *service, const WCHAR *name, ITask **task)
|
2008-08-04 20:43:21 +02:00
|
|
|
{
|
2018-04-24 10:13:31 +02:00
|
|
|
static const WCHAR tasksW[] = { '\\','T','a','s','k','s','\\',0 };
|
|
|
|
static const WCHAR jobW[] = { '.','j','o','b',0 };
|
2008-08-04 20:43:21 +02:00
|
|
|
TaskImpl *This;
|
2018-04-24 10:13:31 +02:00
|
|
|
WCHAR task_name[MAX_PATH];
|
2018-03-30 10:58:18 +02:00
|
|
|
ITaskDefinition *taskdef;
|
2018-03-30 10:59:47 +02:00
|
|
|
IActionCollection *actions;
|
2018-03-13 09:04:07 +01:00
|
|
|
HRESULT hr;
|
2008-08-04 20:43:21 +02:00
|
|
|
|
2018-04-24 10:13:31 +02:00
|
|
|
TRACE("(%s, %p)\n", debugstr_w(name), task);
|
|
|
|
|
|
|
|
if (strchrW(name, '.')) return E_INVALIDARG;
|
|
|
|
|
|
|
|
GetWindowsDirectoryW(task_name, MAX_PATH);
|
|
|
|
lstrcatW(task_name, tasksW);
|
|
|
|
lstrcatW(task_name, name);
|
|
|
|
lstrcatW(task_name, jobW);
|
2018-03-13 09:04:07 +01:00
|
|
|
|
2018-03-30 10:58:18 +02:00
|
|
|
hr = ITaskService_NewTask(service, 0, &taskdef);
|
2018-03-13 09:04:07 +01:00
|
|
|
if (hr != S_OK) return hr;
|
2008-08-04 20:43:21 +02:00
|
|
|
|
2018-04-26 07:46:46 +02:00
|
|
|
This = heap_alloc(sizeof(*This));
|
2008-08-04 20:43:21 +02:00
|
|
|
if (!This)
|
2018-03-13 09:04:07 +01:00
|
|
|
{
|
2018-03-30 10:58:18 +02:00
|
|
|
ITaskDefinition_Release(taskdef);
|
2008-08-04 20:43:21 +02:00
|
|
|
return E_OUTOFMEMORY;
|
2018-03-13 09:04:07 +01:00
|
|
|
}
|
2008-08-04 20:43:21 +02:00
|
|
|
|
2011-01-24 00:17:58 +01:00
|
|
|
This->ITask_iface.lpVtbl = &MSTASK_ITaskVtbl;
|
|
|
|
This->IPersistFile_iface.lpVtbl = &MSTASK_IPersistFileVtbl;
|
2008-08-04 20:43:21 +02:00
|
|
|
This->ref = 1;
|
2018-03-30 10:58:18 +02:00
|
|
|
This->task = taskdef;
|
|
|
|
This->task_name = heap_strdupW(task_name);
|
2018-05-11 06:36:31 +02:00
|
|
|
This->flags = 0;
|
2018-04-20 10:37:08 +02:00
|
|
|
This->status = SCHED_S_TASK_NOT_SCHEDULED;
|
2018-05-15 10:26:52 +02:00
|
|
|
This->exit_code = 0;
|
2018-04-20 10:37:18 +02:00
|
|
|
This->idle_minutes = 10;
|
|
|
|
This->deadline_minutes = 60;
|
2018-04-20 10:37:21 +02:00
|
|
|
This->priority = NORMAL_PRIORITY_CLASS;
|
2008-08-21 22:07:00 +02:00
|
|
|
This->accountName = NULL;
|
2018-04-24 10:13:43 +02:00
|
|
|
This->trigger_count = 0;
|
2018-04-24 10:13:47 +02:00
|
|
|
This->trigger = NULL;
|
2018-04-26 07:46:52 +02:00
|
|
|
This->is_dirty = FALSE;
|
2018-05-11 06:36:31 +02:00
|
|
|
This->instance_count = 0;
|
2008-08-04 20:43:21 +02:00
|
|
|
|
2018-05-31 06:20:14 +02:00
|
|
|
memset(&This->last_runtime, 0, sizeof(This->last_runtime));
|
2018-05-24 10:29:26 +02:00
|
|
|
CoCreateGuid(&This->uuid);
|
|
|
|
|
2008-08-21 22:06:19 +02:00
|
|
|
/* Default time is 3 days = 259200000 ms */
|
|
|
|
This->maxRunTime = 259200000;
|
|
|
|
|
2018-03-30 10:59:47 +02:00
|
|
|
hr = ITaskDefinition_get_Actions(This->task, &actions);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = IActionCollection_Create(actions, TASK_ACTION_EXEC, (IAction **)&This->action);
|
|
|
|
IActionCollection_Release(actions);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
*task = &This->ITask_iface;
|
|
|
|
InterlockedIncrement(&dll_ref);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ITaskDefinition_Release(This->task);
|
|
|
|
ITask_Release(&This->ITask_iface);
|
|
|
|
return hr;
|
2008-08-04 20:43:21 +02:00
|
|
|
}
|