2008-07-18 01:56:14 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Google (Roy Shea)
|
2018-03-13 09:04:03 +01:00
|
|
|
* Copyright (C) 2018 Dmitry Timoshkov
|
2008-07-18 01:56:14 +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"
|
|
|
|
#include "initguid.h"
|
|
|
|
#include "objbase.h"
|
2018-03-13 09:04:03 +01:00
|
|
|
#include "taskschd.h"
|
2018-03-13 09:04:01 +01:00
|
|
|
#include "mstask.h"
|
2008-07-18 01:56:14 +02:00
|
|
|
#include "mstask_private.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mstask);
|
|
|
|
|
2011-01-24 00:14:53 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
ITaskScheduler ITaskScheduler_iface;
|
|
|
|
LONG ref;
|
2018-03-13 09:04:03 +01:00
|
|
|
ITaskService *service;
|
2011-01-24 00:14:53 +01:00
|
|
|
} TaskSchedulerImpl;
|
|
|
|
|
2015-03-20 06:32:36 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
IEnumWorkItems IEnumWorkItems_iface;
|
|
|
|
LONG ref;
|
2018-06-11 11:24:31 +02:00
|
|
|
HANDLE handle;
|
2015-03-20 06:32:36 +01:00
|
|
|
} EnumWorkItemsImpl;
|
|
|
|
|
2011-01-24 00:14:53 +01:00
|
|
|
static inline TaskSchedulerImpl *impl_from_ITaskScheduler(ITaskScheduler *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, TaskSchedulerImpl, ITaskScheduler_iface);
|
|
|
|
}
|
|
|
|
|
2015-03-20 06:32:36 +01:00
|
|
|
static inline EnumWorkItemsImpl *impl_from_IEnumWorkItems(IEnumWorkItems *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, EnumWorkItemsImpl, IEnumWorkItems_iface);
|
|
|
|
}
|
|
|
|
|
2008-07-18 01:56:14 +02:00
|
|
|
static void TaskSchedulerDestructor(TaskSchedulerImpl *This)
|
|
|
|
{
|
|
|
|
TRACE("%p\n", This);
|
2018-03-13 09:04:03 +01:00
|
|
|
ITaskService_Release(This->service);
|
2018-04-26 07:46:46 +02:00
|
|
|
heap_free(This);
|
2008-07-23 01:54:07 +02:00
|
|
|
InterlockedDecrement(&dll_ref);
|
2008-07-18 01:56:14 +02:00
|
|
|
}
|
|
|
|
|
2015-03-20 06:32:36 +01:00
|
|
|
static HRESULT WINAPI EnumWorkItems_QueryInterface(IEnumWorkItems *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
EnumWorkItemsImpl *This = impl_from_IEnumWorkItems(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IEnumWorkItems) || IsEqualGUID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
*obj = &This->IEnumWorkItems_iface;
|
|
|
|
IEnumWorkItems_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI EnumWorkItems_AddRef(IEnumWorkItems *iface)
|
|
|
|
{
|
|
|
|
EnumWorkItemsImpl *This = impl_from_IEnumWorkItems(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p)->(%u)\n", This, ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI EnumWorkItems_Release(IEnumWorkItems *iface)
|
|
|
|
{
|
|
|
|
EnumWorkItemsImpl *This = impl_from_IEnumWorkItems(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%u)\n", This, ref);
|
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
2018-06-11 11:24:31 +02:00
|
|
|
if (This->handle != INVALID_HANDLE_VALUE)
|
|
|
|
FindClose(This->handle);
|
2018-04-26 07:46:46 +02:00
|
|
|
heap_free(This);
|
2015-03-20 06:32:36 +01:00
|
|
|
InterlockedDecrement(&dll_ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2018-06-11 11:24:31 +02:00
|
|
|
static void free_list(LPWSTR *list, LONG count)
|
|
|
|
{
|
|
|
|
LONG i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
CoTaskMemFree(list[i]);
|
|
|
|
|
|
|
|
CoTaskMemFree(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BOOL is_file(const WIN32_FIND_DATAW *data)
|
|
|
|
{
|
|
|
|
return !(data->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
|
|
|
}
|
|
|
|
|
2015-03-20 06:32:36 +01:00
|
|
|
static HRESULT WINAPI EnumWorkItems_Next(IEnumWorkItems *iface, ULONG count, LPWSTR **names, ULONG *fetched)
|
|
|
|
{
|
2018-06-11 11:24:31 +02:00
|
|
|
static const WCHAR tasksW[] = { '\\','T','a','s','k','s','\\','*',0 };
|
2015-03-20 06:32:36 +01:00
|
|
|
EnumWorkItemsImpl *This = impl_from_IEnumWorkItems(iface);
|
2018-06-11 11:24:31 +02:00
|
|
|
WCHAR path[MAX_PATH];
|
|
|
|
WIN32_FIND_DATAW data;
|
|
|
|
ULONG enumerated, allocated, dummy;
|
|
|
|
LPWSTR *list;
|
|
|
|
HRESULT hr = S_FALSE;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%u %p %p)\n", This, count, names, fetched);
|
|
|
|
|
|
|
|
if (!count || !names || (!fetched && count > 1)) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (!fetched) fetched = &dummy;
|
|
|
|
|
|
|
|
*names = NULL;
|
|
|
|
*fetched = 0;
|
|
|
|
enumerated = 0;
|
|
|
|
list = NULL;
|
|
|
|
|
|
|
|
if (This->handle == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
GetWindowsDirectoryW(path, MAX_PATH);
|
|
|
|
lstrcatW(path, tasksW);
|
|
|
|
This->handle = FindFirstFileW(path, &data);
|
|
|
|
if (This->handle == INVALID_HANDLE_VALUE)
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!FindNextFileW(This->handle, &data))
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2019-02-06 11:48:19 +01:00
|
|
|
allocated = 64;
|
|
|
|
list = CoTaskMemAlloc(allocated * sizeof(list[0]));
|
|
|
|
if (!list) return E_OUTOFMEMORY;
|
|
|
|
|
2018-06-11 11:24:31 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (is_file(&data))
|
|
|
|
{
|
|
|
|
if (enumerated >= allocated)
|
|
|
|
{
|
|
|
|
LPWSTR *new_list;
|
|
|
|
allocated *= 2;
|
|
|
|
new_list = CoTaskMemRealloc(list, allocated * sizeof(list[0]));
|
|
|
|
if (!new_list)
|
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
list = new_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
list[enumerated] = CoTaskMemAlloc((lstrlenW(data.cFileName) + 1) * sizeof(WCHAR));
|
|
|
|
if (!list[enumerated])
|
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
lstrcpyW(list[enumerated], data.cFileName);
|
|
|
|
enumerated++;
|
|
|
|
|
|
|
|
if (enumerated >= count)
|
|
|
|
{
|
|
|
|
hr = S_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (FindNextFileW(This->handle, &data));
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
free_list(list, enumerated);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*fetched = enumerated;
|
|
|
|
*names = list;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2015-03-20 06:32:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI EnumWorkItems_Skip(IEnumWorkItems *iface, ULONG count)
|
|
|
|
{
|
2018-06-11 11:24:36 +02:00
|
|
|
LPWSTR *names;
|
|
|
|
ULONG fetched;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%u)\n", iface, count);
|
|
|
|
|
|
|
|
hr = EnumWorkItems_Next(iface, count, &names, &fetched);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
free_list(names, fetched);
|
|
|
|
|
|
|
|
return hr;
|
2015-03-20 06:32:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI EnumWorkItems_Reset(IEnumWorkItems *iface)
|
|
|
|
{
|
|
|
|
EnumWorkItemsImpl *This = impl_from_IEnumWorkItems(iface);
|
2018-06-11 11:24:34 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
if (This->handle != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
FindClose(This->handle);
|
|
|
|
This->handle = INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2015-03-20 06:32:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI EnumWorkItems_Clone(IEnumWorkItems *iface, IEnumWorkItems **cloned)
|
|
|
|
{
|
|
|
|
EnumWorkItemsImpl *This = impl_from_IEnumWorkItems(iface);
|
|
|
|
FIXME("(%p)->(%p): stub\n", This, cloned);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IEnumWorkItemsVtbl EnumWorkItemsVtbl = {
|
|
|
|
EnumWorkItems_QueryInterface,
|
|
|
|
EnumWorkItems_AddRef,
|
|
|
|
EnumWorkItems_Release,
|
|
|
|
EnumWorkItems_Next,
|
|
|
|
EnumWorkItems_Skip,
|
|
|
|
EnumWorkItems_Reset,
|
|
|
|
EnumWorkItems_Clone
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT create_task_enum(IEnumWorkItems **ret)
|
|
|
|
{
|
|
|
|
EnumWorkItemsImpl *tasks;
|
|
|
|
|
|
|
|
*ret = NULL;
|
|
|
|
|
2018-04-26 07:46:46 +02:00
|
|
|
tasks = heap_alloc(sizeof(*tasks));
|
2015-03-20 06:32:36 +01:00
|
|
|
if (!tasks)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
tasks->IEnumWorkItems_iface.lpVtbl = &EnumWorkItemsVtbl;
|
|
|
|
tasks->ref = 1;
|
2018-06-11 11:24:31 +02:00
|
|
|
tasks->handle = INVALID_HANDLE_VALUE;
|
2015-03-20 06:32:36 +01:00
|
|
|
|
|
|
|
*ret = &tasks->IEnumWorkItems_iface;
|
|
|
|
InterlockedIncrement(&dll_ref);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-07-18 01:56:14 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_QueryInterface(
|
|
|
|
ITaskScheduler* iface,
|
|
|
|
REFIID riid,
|
|
|
|
void **ppvObject)
|
|
|
|
{
|
2011-01-24 00:14:53 +01:00
|
|
|
TaskSchedulerImpl * This = impl_from_ITaskScheduler(iface);
|
2008-07-18 01:56:14 +02:00
|
|
|
|
|
|
|
TRACE("IID: %s\n", debugstr_guid(riid));
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualGUID(riid, &IID_ITaskScheduler))
|
|
|
|
{
|
2011-01-24 00:14:53 +01:00
|
|
|
*ppvObject = &This->ITaskScheduler_iface;
|
2008-07-18 01:56:14 +02:00
|
|
|
ITaskScheduler_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppvObject = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MSTASK_ITaskScheduler_AddRef(
|
|
|
|
ITaskScheduler* iface)
|
|
|
|
{
|
2011-01-24 00:14:53 +01:00
|
|
|
TaskSchedulerImpl *This = impl_from_ITaskScheduler(iface);
|
2008-07-18 01:56:14 +02:00
|
|
|
TRACE("\n");
|
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MSTASK_ITaskScheduler_Release(
|
|
|
|
ITaskScheduler* iface)
|
|
|
|
{
|
2011-01-24 00:14:53 +01:00
|
|
|
TaskSchedulerImpl * This = impl_from_ITaskScheduler(iface);
|
2008-07-18 01:56:14 +02:00
|
|
|
ULONG ref;
|
|
|
|
TRACE("\n");
|
|
|
|
ref = InterlockedDecrement(&This->ref);
|
|
|
|
if (ref == 0)
|
|
|
|
TaskSchedulerDestructor(This);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_SetTargetComputer(
|
2018-03-13 09:04:03 +01:00
|
|
|
ITaskScheduler *iface, LPCWSTR comp_name)
|
2008-07-18 01:56:14 +02:00
|
|
|
{
|
2012-11-08 00:12:47 +01:00
|
|
|
TaskSchedulerImpl *This = impl_from_ITaskScheduler(iface);
|
2018-03-13 09:04:03 +01:00
|
|
|
VARIANT v_null, v_comp;
|
|
|
|
HRESULT hr;
|
2012-11-08 00:12:47 +01:00
|
|
|
|
2018-03-13 09:04:03 +01:00
|
|
|
TRACE("(%p)->(%s)\n", This, debugstr_w(comp_name));
|
2012-11-08 00:12:47 +01:00
|
|
|
|
2018-03-13 09:04:03 +01:00
|
|
|
V_VT(&v_null) = VT_NULL;
|
|
|
|
V_VT(&v_comp) = VT_BSTR;
|
|
|
|
V_BSTR(&v_comp) = SysAllocString(comp_name);
|
|
|
|
hr = ITaskService_Connect(This->service, v_comp, v_null, v_null, v_null);
|
|
|
|
SysFreeString(V_BSTR(&v_comp));
|
|
|
|
return hr;
|
2008-07-18 01:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_GetTargetComputer(
|
2018-03-13 09:04:03 +01:00
|
|
|
ITaskScheduler *iface, LPWSTR *comp_name)
|
2008-07-18 01:56:14 +02:00
|
|
|
{
|
2012-11-06 00:20:12 +01:00
|
|
|
TaskSchedulerImpl *This = impl_from_ITaskScheduler(iface);
|
2018-03-13 09:04:03 +01:00
|
|
|
BSTR bstr;
|
|
|
|
WCHAR *buffer;
|
|
|
|
HRESULT hr;
|
2012-11-06 00:20:12 +01:00
|
|
|
|
2018-03-13 09:04:03 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, comp_name);
|
2012-11-06 00:20:12 +01:00
|
|
|
|
2018-03-13 09:04:03 +01:00
|
|
|
if (!comp_name)
|
2012-11-06 00:20:12 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2018-03-13 09:04:03 +01:00
|
|
|
hr = ITaskService_get_TargetServer(This->service, &bstr);
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
2012-11-06 00:20:12 +01:00
|
|
|
/* extra space for two '\' and a zero */
|
2018-03-13 09:04:03 +01:00
|
|
|
buffer = CoTaskMemAlloc((SysStringLen(bstr) + 3) * sizeof(WCHAR));
|
2012-11-06 00:20:12 +01:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
buffer[0] = '\\';
|
|
|
|
buffer[1] = '\\';
|
2018-03-13 09:04:03 +01:00
|
|
|
lstrcpyW(buffer + 2, bstr);
|
|
|
|
*comp_name = buffer;
|
|
|
|
hr = S_OK;
|
2012-11-06 00:20:12 +01:00
|
|
|
}
|
2018-03-13 09:04:03 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*comp_name = NULL;
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
SysFreeString(bstr);
|
|
|
|
return hr;
|
2008-07-18 01:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_Enum(
|
|
|
|
ITaskScheduler* iface,
|
2015-03-20 06:32:36 +01:00
|
|
|
IEnumWorkItems **tasks)
|
2008-07-18 01:56:14 +02:00
|
|
|
{
|
2015-03-20 06:32:36 +01:00
|
|
|
TaskSchedulerImpl *This = impl_from_ITaskScheduler(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, tasks);
|
|
|
|
|
|
|
|
if (!tasks)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
return create_task_enum(tasks);
|
2008-07-18 01:56:14 +02:00
|
|
|
}
|
|
|
|
|
2018-04-25 05:34:46 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_Activate(ITaskScheduler *iface,
|
|
|
|
LPCWSTR task_name, REFIID riid, IUnknown **unknown)
|
2008-07-18 01:56:14 +02:00
|
|
|
{
|
2018-04-25 05:34:46 +02:00
|
|
|
ITask *task;
|
|
|
|
IPersistFile *pfile;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %s, %s, %p\n", iface, debugstr_w(task_name), debugstr_guid(riid), unknown);
|
|
|
|
|
|
|
|
hr = ITaskScheduler_NewWorkItem(iface, task_name, &CLSID_CTask, riid, (IUnknown **)&task);
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
|
|
|
hr = ITask_QueryInterface(task, &IID_IPersistFile, (void **)&pfile);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
WCHAR *curfile;
|
|
|
|
|
|
|
|
hr = IPersistFile_GetCurFile(pfile, &curfile);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = IPersistFile_Load(pfile, curfile, STGM_READ | STGM_SHARE_DENY_WRITE);
|
|
|
|
CoTaskMemFree(curfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
IPersistFile_Release(pfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hr == S_OK)
|
|
|
|
*unknown = (IUnknown *)task;
|
|
|
|
else
|
|
|
|
ITask_Release(task);
|
|
|
|
return hr;
|
2008-07-18 01:56:14 +02:00
|
|
|
}
|
|
|
|
|
2018-05-11 06:36:23 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_Delete(ITaskScheduler *iface, LPCWSTR name)
|
2008-07-18 01:56:14 +02:00
|
|
|
{
|
2018-05-11 06:36:23 +02:00
|
|
|
static const WCHAR tasksW[] = { '\\','T','a','s','k','s','\\',0 };
|
|
|
|
static const WCHAR jobW[] = { '.','j','o','b',0 };
|
|
|
|
WCHAR task_name[MAX_PATH];
|
|
|
|
|
|
|
|
TRACE("%p, %s\n", iface, debugstr_w(name));
|
|
|
|
|
|
|
|
if (strchrW(name, '.')) return E_INVALIDARG;
|
|
|
|
|
|
|
|
GetWindowsDirectoryW(task_name, MAX_PATH);
|
|
|
|
lstrcatW(task_name, tasksW);
|
|
|
|
lstrcatW(task_name, name);
|
|
|
|
lstrcatW(task_name, jobW);
|
|
|
|
|
|
|
|
if (!DeleteFileW(task_name))
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
|
|
|
|
return S_OK;
|
2008-07-18 01:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_NewWorkItem(
|
|
|
|
ITaskScheduler* iface,
|
2018-03-13 09:04:07 +01:00
|
|
|
LPCWSTR task_name,
|
2008-07-18 01:56:14 +02:00
|
|
|
REFCLSID rclsid,
|
|
|
|
REFIID riid,
|
2018-03-13 09:04:07 +01:00
|
|
|
IUnknown **task)
|
2008-07-18 01:56:14 +02:00
|
|
|
{
|
2018-03-13 09:04:07 +01:00
|
|
|
TaskSchedulerImpl *This = impl_from_ITaskScheduler(iface);
|
|
|
|
|
|
|
|
TRACE("(%p, %s, %s, %s, %p)\n", iface, debugstr_w(task_name),
|
|
|
|
debugstr_guid(rclsid), debugstr_guid(riid), task);
|
2008-08-04 20:46:14 +02:00
|
|
|
|
|
|
|
if (!IsEqualGUID(rclsid, &CLSID_CTask))
|
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
|
|
|
|
|
|
|
if (!IsEqualGUID(riid, &IID_ITask))
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
2018-03-30 10:58:18 +02:00
|
|
|
return TaskConstructor(This->service, task_name, (ITask **)task);
|
2008-07-18 01:56:14 +02:00
|
|
|
}
|
|
|
|
|
2018-04-25 05:34:52 +02:00
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_AddWorkItem(ITaskScheduler *iface, LPCWSTR name, IScheduledWorkItem *item)
|
2008-07-18 01:56:14 +02:00
|
|
|
{
|
2018-04-25 05:34:52 +02:00
|
|
|
static const WCHAR tasksW[] = { '\\','T','a','s','k','s','\\',0 };
|
|
|
|
static const WCHAR jobW[] = { '.','j','o','b',0 };
|
|
|
|
WCHAR task_name[MAX_PATH];
|
|
|
|
IPersistFile *pfile;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %s, %p\n", iface, debugstr_w(name), item);
|
|
|
|
|
|
|
|
if (strchrW(name, '.')) return E_INVALIDARG;
|
|
|
|
|
|
|
|
GetWindowsDirectoryW(task_name, MAX_PATH);
|
|
|
|
lstrcatW(task_name, tasksW);
|
|
|
|
lstrcatW(task_name, name);
|
|
|
|
lstrcatW(task_name, jobW);
|
|
|
|
|
|
|
|
hr = IScheduledWorkItem_QueryInterface(item, &IID_IPersistFile, (void **)&pfile);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = IPersistFile_Save(pfile, task_name, TRUE);
|
|
|
|
IPersistFile_Release(pfile);
|
|
|
|
}
|
|
|
|
return hr;
|
2008-07-18 01:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_IsOfType(
|
|
|
|
ITaskScheduler* iface,
|
|
|
|
LPCWSTR pwszName,
|
|
|
|
REFIID riid)
|
|
|
|
{
|
|
|
|
FIXME("%p, %s, %s: stub\n", iface, debugstr_w(pwszName),
|
|
|
|
debugstr_guid(riid));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const ITaskSchedulerVtbl MSTASK_ITaskSchedulerVtbl =
|
|
|
|
{
|
|
|
|
MSTASK_ITaskScheduler_QueryInterface,
|
|
|
|
MSTASK_ITaskScheduler_AddRef,
|
|
|
|
MSTASK_ITaskScheduler_Release,
|
|
|
|
MSTASK_ITaskScheduler_SetTargetComputer,
|
|
|
|
MSTASK_ITaskScheduler_GetTargetComputer,
|
|
|
|
MSTASK_ITaskScheduler_Enum,
|
|
|
|
MSTASK_ITaskScheduler_Activate,
|
|
|
|
MSTASK_ITaskScheduler_Delete,
|
|
|
|
MSTASK_ITaskScheduler_NewWorkItem,
|
|
|
|
MSTASK_ITaskScheduler_AddWorkItem,
|
|
|
|
MSTASK_ITaskScheduler_IsOfType
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT TaskSchedulerConstructor(LPVOID *ppObj)
|
|
|
|
{
|
|
|
|
TaskSchedulerImpl *This;
|
2018-03-13 09:04:03 +01:00
|
|
|
ITaskService *service;
|
|
|
|
VARIANT v_null;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2008-07-18 01:56:14 +02:00
|
|
|
TRACE("(%p)\n", ppObj);
|
|
|
|
|
2018-03-13 09:04:03 +01:00
|
|
|
hr = CoCreateInstance(&CLSID_TaskScheduler, NULL, CLSCTX_INPROC_SERVER, &IID_ITaskService, (void **)&service);
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
|
|
|
V_VT(&v_null) = VT_NULL;
|
|
|
|
hr = ITaskService_Connect(service, v_null, v_null, v_null, v_null);
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
ITaskService_Release(service);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2018-04-26 07:46:46 +02:00
|
|
|
This = heap_alloc(sizeof(*This));
|
2008-07-18 01:56:14 +02:00
|
|
|
if (!This)
|
2018-03-13 09:04:03 +01:00
|
|
|
{
|
|
|
|
ITaskService_Release(service);
|
2008-07-18 01:56:14 +02:00
|
|
|
return E_OUTOFMEMORY;
|
2018-03-13 09:04:03 +01:00
|
|
|
}
|
2008-07-18 01:56:14 +02:00
|
|
|
|
2011-01-24 00:14:53 +01:00
|
|
|
This->ITaskScheduler_iface.lpVtbl = &MSTASK_ITaskSchedulerVtbl;
|
2018-03-13 09:04:03 +01:00
|
|
|
This->service = service;
|
2008-07-18 01:56:14 +02:00
|
|
|
This->ref = 1;
|
|
|
|
|
2011-01-24 00:14:53 +01:00
|
|
|
*ppObj = &This->ITaskScheduler_iface;
|
2008-07-23 01:54:07 +02:00
|
|
|
InterlockedIncrement(&dll_ref);
|
2008-07-18 01:56:14 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|