ReactOS  0.4.12-dev-720-g6accaef
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)
31  ServiceInfo.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
32 
33  if (!ServiceInfo.dwStartType)
34  ServiceInfo.dwStartType = SERVICE_DEMAND_START;
35 
36  if (!ServiceInfo.dwErrorControl)
37  ServiceInfo.dwErrorControl = SERVICE_ERROR_NORMAL;
38 
39  if (ServiceInfo.lpDependencies)
40  {
41  Length = lstrlen(ServiceInfo.lpDependencies);
42 
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)
112 
113  if (lpBuffer != NULL)
115 
116  return bRet;
117 }
#define _tprintf
Definition: tchar.h:506
#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 WINAPI GetLastError(VOID)
Definition: except.c:1059
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
#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
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:163
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
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)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
SC_HANDLE hSCManager
Definition: sc.c:12
#define lstrlen
Definition: winbase.h:3690
VOID ReportLastError(VOID)
Definition: sc.c:15
#define SERVICE_DEMAND_START
Definition: cmtypes.h:976
#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