minor corrections by M.Taguchi
[reactos.git] / reactos / apps / utils / sc / command.c
1 /*
2 * ReactOS SC - service control console program
3 *
4 * command.c
5 *
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include <windows.h>
24 #include <wchar.h>
25 #include <tchar.h>
26 #include "main.h"
27
28
29 int sc_Lock(SC_HANDLE hSCManager)
30 {
31 dprintf("sc_Lock(%x) - not implemented.\n", hSCManager);
32 return 0;
33 }
34
35 int sc_QueryLock(SC_HANDLE hSCManager)
36 {
37 QUERY_SERVICE_LOCK_STATUS LockStatus;
38 DWORD cbBufSize = sizeof(QUERY_SERVICE_LOCK_STATUS);
39 DWORD cbBytesNeeded;
40
41 dprintf("sc_QueryLock() - called.\n");
42
43 if (QueryServiceLockStatus(hSCManager, &LockStatus, cbBufSize, &cbBytesNeeded)) {
44
45 } else {
46 dprintf("Failed to Query Service Lock Status.\n");
47 ReportLastError();
48 }
49
50 if (!CloseServiceHandle(hSCManager)) {
51 dprintf("Failed to CLOSE handle to SCM.\n");
52 ReportLastError();
53 }
54
55 return 0;
56 }
57
58 int sc_control(SC_HANDLE hSCManager, char* service, DWORD dwControl)
59 {
60 int ret = 0;
61 SC_HANDLE schService;
62 SERVICE_STATUS serviceStatus;
63
64 dprintf("sc_control(%x, %s, %d) - called.\n", hSCManager, service, dwControl);
65
66 schService = OpenServiceA(hSCManager, service, SERVICE_ALL_ACCESS);
67 if (schService != NULL) {
68 ret = ControlService(schService, dwControl, &serviceStatus);
69 dprintf("ControlService(%x, %x, %x) returned %d\n", schService, dwControl, &serviceStatus, ret);
70 if (!ret) {
71
72
73 }
74 CloseServiceHandle(schService);
75 }
76 return ret;
77 }
78
79 int sc_command(SC_HANDLE hSCManager, SC_CMDS sc_cmd, char* argv[])
80 {
81 // dprintf("sc_command(%x, %d, %s) - called.\n", hSCManager, sc_cmd, argv[]);
82 switch (sc_cmd) {
83 case SC_CMD_START:
84 //return sc_control(hSCManager, sc_cmd_arg, SERVICE_CONTROL_START);
85 dprintf(" - not implemented.\n");
86 break;
87 case SC_CMD_PAUSE:
88 return sc_control(hSCManager, argv[0], SERVICE_CONTROL_PAUSE);
89 case SC_CMD_INTERROGATE:
90 return sc_control(hSCManager, argv[0], SERVICE_CONTROL_INTERROGATE);
91 case SC_CMD_CONTINUE:
92 return sc_control(hSCManager, argv[0], SERVICE_CONTROL_CONTINUE);
93 case SC_CMD_STOP:
94 return sc_control(hSCManager, argv[0], SERVICE_CONTROL_STOP);
95
96 // case SC_CMD_CONFIG:
97 // case SC_CMD_DESCRIPTION:
98 // case SC_CMD_CONTROL:
99
100 case SC_CMD_LOCK:
101 return sc_Lock(hSCManager);
102 case SC_CMD_QUERYLOCK:
103 return sc_QueryLock(hSCManager);
104 default:
105 dprintf("sc_command(%x, %d, %s) - unknown command.\n", hSCManager, sc_cmd, argv[0]);
106 break;
107 }
108 return 0;
109 }