ReactOS 0.4.15-dev-5666-gc548b97
create.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/create.c
5 * PURPOSE: Create a service
6 * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
7 * Roel Messiant <roelmessiant@gmail.com>
8 *
9 */
10
11#include "sc.h"
12
13BOOL Create(LPCTSTR *ServiceArgs, INT ArgCount)
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 {
27 return FALSE;
28 }
29
30 if (!ServiceInfo.dwServiceType)
32
33 if (!ServiceInfo.dwStartType)
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
103done:
104 if (bRet == FALSE)
106
107 if (hService)
108 CloseServiceHandle(hService);
109
110 if (hSCManager)
112
113 if (lpBuffer != NULL)
115
116 return bRet;
117}
BOOL ParseCreateConfigArguments(LPCTSTR *ServiceArgs, INT ArgCount, BOOL bChangeService, OUT LPSERVICE_CREATE_INFO lpServiceInfo)
Definition: misc.c:53
@ Create
Definition: registry.c:563
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
#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 HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned int BOOL
Definition: ntddk_ex.h:94
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
#define _tprintf
Definition: tchar.h:506
DWORD ReportLastError(void)
Definition: loadlib.c:67
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
SC_HANDLE hSCManager
Definition: sc.c:12
VOID CreateUsage(VOID)
Definition: usage.c:146
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
int32_t INT
Definition: typedefs.h:58
JS_SERVICE_STATE ServiceInfo(LPCTSTR ServiceName)
Return service status by service name.
Definition: user_lib.cpp:157
#define _T(x)
Definition: vfdio.h:22
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define lstrlen
Definition: winbase.h:3747
#define OpenSCManager
Definition: winsvc.h:575
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
#define CreateService
Definition: winsvc.h:569
#define SC_MANAGER_CREATE_SERVICE
Definition: winsvc.h:15
#define SERVICE_DEMAND_START
Definition: cmtypes.h:978
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:962
#define SERVICE_ERROR_NORMAL
Definition: cmtypes.h:982
char TCHAR
Definition: xmlstorage.h:189
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
CHAR * LPTSTR
Definition: xmlstorage.h:192