ReactOS 0.4.16-dev-329-g9223134
start.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/sc/start.c
5 * PURPOSE: Start a service
6 * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
7 *
8 */
9
10#include "sc.h"
11
12BOOL Start(LPCTSTR ServiceName, LPCTSTR *ServiceArgs, INT ArgCount)
13{
14 SC_HANDLE hSCManager = NULL;
15 SC_HANDLE hSc = NULL;
16 LPSERVICE_STATUS_PROCESS pServiceInfo = NULL;
17 BOOL bResult = TRUE;
18
19#ifdef SCDBG
20 LPCTSTR *TmpArgs = ServiceArgs;
21 INT TmpCnt = ArgCount;
22 _tprintf(_T("service to control - %s\n"), ServiceName);
23 _tprintf(_T("Arguments:\n"));
24 while (TmpCnt)
25 {
26 _tprintf(_T(" %s\n"), *TmpArgs);
27 TmpArgs++;
28 TmpCnt--;
29 }
30 _tprintf(_T("\n"));
31#endif /* SCDBG */
32
34 NULL,
36 if (hSCManager == NULL)
37 {
38 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
39 bResult = FALSE;
40 goto done;
41 }
42
46 if (hSc == NULL)
47 {
48 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
49 bResult = FALSE;
50 goto done;
51 }
52
53 if (!ArgCount)
54 {
55 ServiceArgs = NULL;
56 }
57
58 if (!StartService(hSc,
59 ArgCount,
60 ServiceArgs))
61 {
62 _tprintf(_T("[SC] StartService FAILED %lu:\n\n"), GetLastError());
63 bResult = FALSE;
64 goto done;
65 }
66
67 pServiceInfo = QueryService(ServiceName);
68 if (pServiceInfo != NULL)
69 {
71 NULL,
72 pServiceInfo,
73 TRUE);
74
75 HeapFree(GetProcessHeap(), 0, pServiceInfo);
76 }
77
78done:
79 if (bResult == FALSE)
81
82 if (hSc)
84
85 if (hSCManager)
87
88 return bResult;
89}
VOID PrintService(LPCTSTR lpServiceName, LPCTSTR lpDisplayName, LPSERVICE_STATUS_PROCESS pStatus, BOOL bExtended)
Definition: print.c:13
LPSERVICE_STATUS_PROCESS QueryService(LPCTSTR ServiceName)
Definition: query.c:13
static WCHAR ServiceName[]
Definition: browser.c:19
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned int BOOL
Definition: ntddk_ex.h:94
return pTarget Start()
#define _tprintf
Definition: tchar.h:506
DWORD ReportLastError(void)
Definition: loadlib.c:67
SC_HANDLE hSCManager
Definition: sc.c:12
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define SERVICE_START
Definition: winsvc.h:57
#define SERVICE_QUERY_STATUS
Definition: winsvc.h:55
#define OpenSCManager
Definition: winsvc.h:575
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
#define StartService
Definition: winsvc.h:585
#define OpenService
Definition: winsvc.h:576
const CHAR * LPCTSTR
Definition: xmlstorage.h:193