2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/system/sc/control.c
5 * PURPOSE: Stops, pauses and resumes a service
6 * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
13 Control(DWORD Control
,
18 SC_HANDLE hSCManager
= NULL
;
20 SERVICE_STATUS Status
;
21 DWORD dwDesiredAccess
= 0;
24 LPCTSTR
*TmpArgs
= Args
;
25 INT TmpCnt
= ArgCount
;
26 _tprintf(_T("service to control - %s\n"), ServiceName
);
27 _tprintf(_T("command - %lu\n"), Control
);
28 _tprintf(_T("Arguments:\n"));
31 _tprintf(_T(" %s\n"), *TmpArgs
);
40 case SERVICE_CONTROL_STOP
:
41 dwDesiredAccess
= SERVICE_STOP
;
44 case SERVICE_CONTROL_PAUSE
:
45 dwDesiredAccess
= SERVICE_PAUSE_CONTINUE
;
48 case SERVICE_CONTROL_CONTINUE
:
49 dwDesiredAccess
= SERVICE_PAUSE_CONTINUE
;
52 case SERVICE_CONTROL_INTERROGATE
:
53 dwDesiredAccess
= SERVICE_INTERROGATE
;
56 case SERVICE_CONTROL_SHUTDOWN
:
62 hSCManager
= OpenSCManager(NULL
,
65 if (hSCManager
!= NULL
)
67 hSc
= OpenService(hSCManager
,
72 if (ControlService(hSc
,
76 SERVICE_STATUS_PROCESS StatusEx
;
78 /* FIXME: lazy hack ;) */
79 CopyMemory(&StatusEx
, &Status
, sizeof(Status
));
80 StatusEx
.dwProcessId
= 0;
81 StatusEx
.dwServiceFlags
= 0;
83 PrintService(ServiceName
,
87 CloseServiceHandle(hSc
);
88 CloseServiceHandle(hSCManager
);
94 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
98 if (hSc
) CloseServiceHandle(hSc
);
99 if (hSCManager
) CloseServiceHandle(hSCManager
);