Skip to content

Commit

Permalink
schedsvc: Mark service as auto-start once a task is registered.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Timoshkov authored and julliard committed Mar 14, 2014
1 parent 79fe437 commit c2148f9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
6 changes: 5 additions & 1 deletion dlls/schedsvc/schedsvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,11 @@ HRESULT __cdecl SchRpcRegisterTask(const WCHAR *path, const WCHAR *xml, DWORD fl
}

hr = write_xml_utf8(full_name, disposition, xml);
if (hr == S_OK) *actual_path = heap_strdupW(relative_path);
if (hr == S_OK)
{
*actual_path = heap_strdupW(relative_path);
schedsvc_auto_start();
}

heap_free(full_name);
return hr;
Expand Down
2 changes: 2 additions & 0 deletions dlls/schedsvc/schedsvc_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "wine/unicode.h"

void schedsvc_auto_start(void) DECLSPEC_HIDDEN;

static void *heap_alloc_zero(SIZE_T size) __WINE_ALLOC_SIZE(1);
static inline void *heap_alloc_zero(SIZE_T size)
{
Expand Down
53 changes: 51 additions & 2 deletions dlls/schedsvc/svc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,60 @@

WINE_DEFAULT_DEBUG_CHANNEL(schedsvc);

static const WCHAR scheduleW[] = {'S','c','h','e','d','u','l','e',0};
static SERVICE_STATUS_HANDLE schedsvc_handle;
static HANDLE done_event;

void schedsvc_auto_start(void)
{
static DWORD start_type;
SC_HANDLE scm, service;
QUERY_SERVICE_CONFIGW *cfg;
DWORD cfg_size;

if (start_type == SERVICE_AUTO_START) return;

TRACE("changing service start type to SERVICE_AUTO_START\n");

scm = OpenSCManagerW(NULL, NULL, 0);
if (!scm)
{
WARN("failed to open SCM (%u)\n", GetLastError());
return;
}

service = OpenServiceW(scm, scheduleW, SERVICE_QUERY_CONFIG | SERVICE_CHANGE_CONFIG);
if (service)
{
if (!QueryServiceConfigW(service, NULL, 0, &cfg_size) && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
cfg = HeapAlloc(GetProcessHeap(), 0, cfg_size);
if (cfg)
{
if (QueryServiceConfigW(service, cfg, cfg_size, &cfg_size))
{
start_type = cfg->dwStartType;
if (start_type != SERVICE_AUTO_START)
{
if (ChangeServiceConfigW(service, SERVICE_NO_CHANGE, SERVICE_AUTO_START, SERVICE_NO_CHANGE,
NULL, NULL, NULL, NULL, NULL, NULL, NULL))
start_type = SERVICE_AUTO_START;
}
}
HeapFree(GetProcessHeap(), 0, cfg);
}
}
else
WARN("failed to query service config (%u)\n", GetLastError());

CloseServiceHandle(service);
}
else
WARN("failed to open service (%u)\n", GetLastError());

CloseServiceHandle(scm);
}

static void schedsvc_update_status(DWORD state)
{
SERVICE_STATUS status;
Expand Down Expand Up @@ -122,8 +173,6 @@ static void RPC_finish(void)

void WINAPI ServiceMain(DWORD argc, LPWSTR *argv)
{
static const WCHAR scheduleW[] = {'S','c','h','e','d','u','l','e',0};

WINE_TRACE("starting Task Scheduler Service\n");

if (RPC_init() != RPC_S_OK) return;
Expand Down

0 comments on commit c2148f9

Please sign in to comment.