2006-02-16 23:18:11 +00:00
|
|
|
/*
|
2006-08-31 17:59:02 +00:00
|
|
|
* PROJECT: ReactOS Services
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2015-09-09 13:13:35 +00:00
|
|
|
* FILE: base/applications/sc/control.c
|
2006-08-31 17:59:02 +00:00
|
|
|
* PURPOSE: Stops, pauses and resumes a service
|
|
|
|
* COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
|
2006-02-16 23:18:11 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sc.h"
|
|
|
|
|
2006-08-31 17:59:02 +00:00
|
|
|
BOOL
|
|
|
|
Control(DWORD Control,
|
|
|
|
LPCTSTR ServiceName,
|
|
|
|
LPCTSTR *Args,
|
|
|
|
INT ArgCount)
|
2006-02-16 23:18:11 +00:00
|
|
|
{
|
2006-08-31 17:59:02 +00:00
|
|
|
SC_HANDLE hSCManager = NULL;
|
2016-06-15 21:28:33 +00:00
|
|
|
SC_HANDLE hService = NULL;
|
2006-02-16 23:18:11 +00:00
|
|
|
SERVICE_STATUS Status;
|
2006-08-31 17:59:02 +00:00
|
|
|
DWORD dwDesiredAccess = 0;
|
2016-06-15 21:28:33 +00:00
|
|
|
BOOL bResult = TRUE;
|
|
|
|
SERVICE_STATUS_PROCESS StatusEx;
|
2006-02-16 23:18:11 +00:00
|
|
|
|
2006-08-31 17:59:02 +00:00
|
|
|
#ifdef SCDBG
|
|
|
|
LPCTSTR *TmpArgs = Args;
|
|
|
|
INT TmpCnt = ArgCount;
|
|
|
|
_tprintf(_T("service to control - %s\n"), ServiceName);
|
|
|
|
_tprintf(_T("command - %lu\n"), Control);
|
|
|
|
_tprintf(_T("Arguments:\n"));
|
|
|
|
while (TmpCnt)
|
2006-02-16 23:18:11 +00:00
|
|
|
{
|
2006-08-31 17:59:02 +00:00
|
|
|
_tprintf(_T(" %s\n"), *TmpArgs);
|
|
|
|
TmpArgs++;
|
|
|
|
TmpCnt--;
|
2006-02-16 23:18:11 +00:00
|
|
|
}
|
2006-08-31 17:59:02 +00:00
|
|
|
_tprintf(_T("\n"));
|
2006-02-16 23:18:11 +00:00
|
|
|
#endif /* SCDBG */
|
|
|
|
|
2006-08-31 17:59:02 +00:00
|
|
|
switch (Control)
|
2006-02-16 23:18:11 +00:00
|
|
|
{
|
2006-08-31 17:59:02 +00:00
|
|
|
case SERVICE_CONTROL_STOP:
|
|
|
|
dwDesiredAccess = SERVICE_STOP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SERVICE_CONTROL_PAUSE:
|
|
|
|
case SERVICE_CONTROL_CONTINUE:
|
2018-02-25 10:07:14 +00:00
|
|
|
case SERVICE_CONTROL_PARAMCHANGE:
|
|
|
|
case SERVICE_CONTROL_NETBINDADD:
|
|
|
|
case SERVICE_CONTROL_NETBINDREMOVE:
|
|
|
|
case SERVICE_CONTROL_NETBINDENABLE:
|
|
|
|
case SERVICE_CONTROL_NETBINDDISABLE:
|
2006-08-31 17:59:02 +00:00
|
|
|
dwDesiredAccess = SERVICE_PAUSE_CONTINUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SERVICE_CONTROL_INTERROGATE:
|
|
|
|
dwDesiredAccess = SERVICE_INTERROGATE;
|
|
|
|
break;
|
|
|
|
|
2018-02-25 10:07:14 +00:00
|
|
|
default:
|
|
|
|
if (Control >= 128 && Control <= 255)
|
|
|
|
dwDesiredAccess = SERVICE_USER_DEFINED_CONTROL;
|
|
|
|
else
|
|
|
|
dwDesiredAccess = 0;
|
2006-08-31 17:59:02 +00:00
|
|
|
break;
|
2006-02-16 23:18:11 +00:00
|
|
|
}
|
|
|
|
|
2006-08-31 17:59:02 +00:00
|
|
|
hSCManager = OpenSCManager(NULL,
|
|
|
|
NULL,
|
|
|
|
SC_MANAGER_CONNECT);
|
2016-06-15 21:28:33 +00:00
|
|
|
if (hSCManager == NULL)
|
2006-02-16 23:18:11 +00:00
|
|
|
{
|
2016-06-15 21:28:33 +00:00
|
|
|
_tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
|
|
|
|
bResult = FALSE;
|
|
|
|
goto done;
|
2006-08-31 17:59:02 +00:00
|
|
|
}
|
2006-02-16 23:18:11 +00:00
|
|
|
|
2016-06-15 21:28:33 +00:00
|
|
|
hService = OpenService(hSCManager,
|
|
|
|
ServiceName,
|
|
|
|
dwDesiredAccess);
|
|
|
|
if (hService == NULL)
|
|
|
|
{
|
|
|
|
_tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
|
|
|
|
bResult = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ControlService(hService,
|
|
|
|
Control,
|
|
|
|
&Status))
|
|
|
|
{
|
|
|
|
_tprintf(_T("[SC] ControlService FAILED %lu:\n\n"), GetLastError());
|
|
|
|
bResult = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: lazy hack ;) */
|
|
|
|
CopyMemory(&StatusEx, &Status, sizeof(Status));
|
|
|
|
StatusEx.dwProcessId = 0;
|
|
|
|
StatusEx.dwServiceFlags = 0;
|
|
|
|
|
|
|
|
PrintService(ServiceName,
|
2018-02-17 18:26:06 +00:00
|
|
|
NULL,
|
2016-06-15 21:28:33 +00:00
|
|
|
&StatusEx,
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (!bResult)
|
|
|
|
ReportLastError();
|
|
|
|
|
|
|
|
if (hService)
|
|
|
|
CloseServiceHandle(hService);
|
|
|
|
|
|
|
|
if (hSCManager)
|
|
|
|
CloseServiceHandle(hSCManager);
|
|
|
|
|
|
|
|
return bResult;
|
2006-02-16 23:18:11 +00:00
|
|
|
}
|