ReactOS  0.4.12-dev-36-g472787f
create.c File Reference
#include "sc.h"
Include dependency graph for create.c:

Go to the source code of this file.

Functions

BOOL Create (LPCTSTR *ServiceArgs, INT ArgCount)
 

Function Documentation

◆ Create()

BOOL Create ( LPCTSTR ServiceArgs,
INT  ArgCount 
)

Definition at line 13 of file create.c.

14 {
15  SC_HANDLE hSCManager = NULL;
16  SC_HANDLE hService = NULL;
17  BOOL bRet = TRUE;
18 
19  INT i;
20  INT Length;
23 
24  if (!ParseCreateConfigArguments(ServiceArgs, ArgCount, FALSE, &ServiceInfo))
25  {
26  CreateUsage();
27  return FALSE;
28  }
29 
30  if (!ServiceInfo.dwServiceType)
32 
33  if (!ServiceInfo.dwStartType)
34  ServiceInfo.dwStartType = SERVICE_DEMAND_START;
35 
36  if (!ServiceInfo.dwErrorControl)
38 
39  if (ServiceInfo.lpDependencies)
40  {
41  Length = lstrlen(ServiceInfo.lpDependencies);
42 
43  lpBuffer = HeapAlloc(GetProcessHeap(),
44  0,
45  (Length + 2) * sizeof(TCHAR));
46 
47  for (i = 0; i < Length; i++)
48  if (ServiceInfo.lpDependencies[i] == _T('/'))
49  lpBuffer[i] = 0;
50  else
51  lpBuffer[i] = ServiceInfo.lpDependencies[i];
52 
53  lpBuffer[Length] = 0;
54  lpBuffer[Length + 1] = 0;
55 
56  ServiceInfo.lpDependencies = lpBuffer;
57  }
58 
59 #ifdef SCDBG
60  _tprintf(_T("service name - %s\n"), ServiceInfo.lpServiceName);
61  _tprintf(_T("display name - %s\n"), ServiceInfo.lpDisplayName);
62  _tprintf(_T("service type - %lu\n"), ServiceInfo.dwServiceType);
63  _tprintf(_T("start type - %lu\n"), ServiceInfo.dwStartType);
64  _tprintf(_T("error control - %lu\n"), ServiceInfo.dwErrorControl);
65  _tprintf(_T("Binary path - %s\n"), ServiceInfo.lpBinaryPathName);
66  _tprintf(_T("load order group - %s\n"), ServiceInfo.lpLoadOrderGroup);
67  _tprintf(_T("tag - %lu\n"), ServiceInfo.dwTagId);
68  _tprintf(_T("dependencies - %s\n"), ServiceInfo.lpDependencies);
69  _tprintf(_T("account start name - %s\n"), ServiceInfo.lpServiceStartName);
70  _tprintf(_T("account password - %s\n"), ServiceInfo.lpPassword);
71 #endif
72 
74  if (hSCManager == NULL)
75  {
76  _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
77  bRet = FALSE;
78  goto done;
79  }
80 
81  hService = CreateService(hSCManager,
82  ServiceInfo.lpServiceName,
83  ServiceInfo.lpDisplayName,
85  ServiceInfo.dwServiceType,
86  ServiceInfo.dwStartType,
87  ServiceInfo.dwErrorControl,
88  ServiceInfo.lpBinaryPathName,
89  ServiceInfo.lpLoadOrderGroup,
90  ServiceInfo.bTagId ? &ServiceInfo.dwTagId : NULL,
91  ServiceInfo.lpDependencies,
92  ServiceInfo.lpServiceStartName,
93  ServiceInfo.lpPassword);
94  if (hService == NULL)
95  {
96  _tprintf(_T("[SC] CreateService FAILED %lu:\n\n"), GetLastError());
97  bRet = FALSE;
98  goto done;
99  }
100 
101  _tprintf(_T("[SC] CreateService SUCCESS\n\n"));
102 
103 done:
104  if (bRet == FALSE)
105  ReportLastError();
106 
107  if (hService)
108  CloseServiceHandle(hService);
109 
110  if (hSCManager)
111  CloseServiceHandle(hSCManager);
112 
113  if (lpBuffer != NULL)
114  HeapFree(GetProcessHeap(), 0, lpBuffer);
115 
116  return bRet;
117 }
#define _tprintf
Definition: tchar.h:506
LPCTSTR lpBinaryPathName
Definition: sc.h:27
#define SERVICE_ERROR_NORMAL
Definition: cmtypes.h:980
#define TRUE
Definition: types.h:120
JS_SERVICE_STATE ServiceInfo(LPCTSTR ServiceName)
Return service status by service name.
Definition: user_lib.cpp:157
DWORD dwServiceType
Definition: sc.h:24
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD dwTagId
Definition: sc.h:29
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
LPCTSTR lpServiceName
Definition: sc.h:22
#define CreateService
Definition: winsvc.h:569
int32_t INT
Definition: typedefs.h:56
CHAR * LPTSTR
Definition: xmlstorage.h:192
VOID CreateUsage(VOID)
Definition: usage.c:146
GLenum GLclampf GLint i
Definition: glfuncs.h:14
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:163
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:576
smooth NULL
Definition: ftsmooth.c:416
#define SC_MANAGER_CREATE_SERVICE
Definition: winsvc.h:15
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:960
char TCHAR
Definition: xmlstorage.h:189
#define OpenSCManager
Definition: winsvc.h:575
#define _T(x)
Definition: vfdio.h:22
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
DWORD dwErrorControl
Definition: sc.h:26
LPCTSTR lpLoadOrderGroup
Definition: sc.h:28
BOOL bTagId
Definition: sc.h:34
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
LPCTSTR lpPassword
Definition: sc.h:32
SC_HANDLE hSCManager
Definition: sc.c:12
DWORD dwStartType
Definition: sc.h:25
#define lstrlen
Definition: winbase.h:3690
VOID ReportLastError(VOID)
Definition: sc.c:15
LPCTSTR lpDependencies
Definition: sc.h:30
#define SERVICE_DEMAND_START
Definition: cmtypes.h:976
LPCTSTR lpDisplayName
Definition: sc.h:23
#define HeapFree(x, y, z)
Definition: compat.h:394
BOOL ParseCreateConfigArguments(LPCTSTR *ServiceArgs, INT ArgCount, BOOL bChangeService, OUT LPSERVICE_CREATE_INFO lpServiceInfo)
Definition: misc.c:53
LPCTSTR lpServiceStartName
Definition: sc.h:31