ReactOS 0.4.15-dev-8145-ga541a46
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/mscutils/servman/create.c
5 * PURPOSE: Create a new service
6 * COPYRIGHT: Copyright 2006-2007 Ged Murphy <gedmurphy@reactos.org>
7 *
8 */
9
10#include "precomp.h"
11
12typedef struct _CREATE_DATA
13{
20
22
24
25static BOOL
27{
28 SC_HANDLE hSCManager;
29 SC_HANDLE hSc;
30 BOOL bRet = FALSE;
31
32 /* open handle to the SCM */
34 NULL,
36 if (hSCManager)
37 {
39 Data->ServiceName,
40 Data->DisplayName,
45 Data->BinPath,
46 NULL,
47 NULL,
48 NULL,
49 NULL,
50 NULL);
51
52 if (hSc)
53 {
54 LPWSTR lpSuccess;
55
56 /* Set the service description as CreateService
57 does not do this for us */
58 SetServiceDescription(Data->ServiceName,
59 Data->Description);
60
61 /* report success to user */
62 if (AllocAndLoadString(&lpSuccess,
65 {
66 DisplayString(lpSuccess);
67
68 LocalFree(lpSuccess);
69 }
70
72 bRet = TRUE;
73 }
74
76 }
77
78 return bRet;
79}
80
81static LPWSTR
83 UINT id)
84{
85 HWND hwnd;
86 LPWSTR lpString = NULL;
87 INT iLen = 0;
88
89 hwnd = GetDlgItem(Data->hSelf,
90 id);
91 if (hwnd)
92 {
94 if (iLen)
95 {
96 lpString = (LPWSTR)HeapAlloc(ProcessHeap,
97 0,
98 (iLen + 1) * sizeof(WCHAR));
99 if (lpString)
100 {
102 lpString,
103 iLen + 1);
104 }
105 }
106 }
107
108 return lpString;
109}
110
111static BOOL
113{
114 BOOL bRet = FALSE;
115
116 if ((Data->ServiceName = GetStringFromDialog(Data, IDC_CREATE_SERVNAME)))
117 {
118 if ((Data->DisplayName = GetStringFromDialog(Data, IDC_CREATE_DISPNAME)))
119 {
120 if ((Data->BinPath = GetStringFromDialog(Data, IDC_CREATE_PATH)))
121 {
124
125 bRet = TRUE;
126 }
127 }
128 }
129
130 return bRet;
131}
132
133static VOID
135{
136 if (Data->ServiceName != NULL)
138 0,
139 Data->ServiceName);
140 if (Data->DisplayName != NULL)
142 0,
143 Data->DisplayName);
144 if (Data->BinPath != NULL)
146 0,
147 Data->BinPath);
148 if (Data->Description != NULL)
150 0,
151 Data->Description);
152 if (Data->Options != NULL)
154 0,
155 Data->Options);
156
158 0,
159 Data);
160}
161
167{
168 HWND hHelp;
169 HICON hIcon = NULL;
170 WCHAR Buf[1000];
171
172 switch (message)
173 {
174 case WM_INITDIALOG:
175 {
179 16,
180 16,
181 0);
182
183 SendMessageW(hDlg,
184 WM_SETICON,
186 (LPARAM)hIcon);
187
188 hHelp = GetDlgItem(hDlg,
190
193 Buf,
194 sizeof(Buf) / sizeof(WCHAR));
195
196 SetWindowTextW(hHelp, Buf);
197
198 return TRUE;
199 }
200
201 case WM_COMMAND:
202 {
203 if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
204 {
207 DestroyWindow(hDlg);
208 return TRUE;
209 }
210 break;
211 }
212 }
213
214 return FALSE;
215}
216
222{
223 HICON hIcon = NULL;
224
225 switch (message)
226 {
227 case WM_INITDIALOG:
228 {
232 16,
233 16,
234 0);
235 if (hIcon)
236 {
237 SendMessage(hDlg,
238 WM_SETICON,
240 (LPARAM)hIcon);
242 }
243
244 return TRUE;
245 }
246
247 case WM_COMMAND:
248 {
249 switch (LOWORD(wParam))
250 {
251 case IDOK:
252 {
254
257 sizeof(CREATE_DATA));
258 if (Data)
259 {
260 Data->hSelf = hDlg;
261
263 {
264 DoCreate(Data);
265 }
266 else
267 {
268 /* Something went wrong, leave the dialog
269 * open so they can try again */
271 break;
272 }
273
275 }
276
277 EndDialog(hDlg,
278 LOWORD(wParam));
279 return TRUE;
280 }
281
282 case IDCANCEL:
283 {
284 EndDialog(hDlg,
285 LOWORD(wParam));
286 return TRUE;
287 }
288
289 case ID_CREATE_HELP:
290 {
291 HWND hHelp;
292
293 if (! bHelpOpen)
294 {
295 hHelp = CreateDialog(hInstance,
297 hDlg,
299 if(hHelp != NULL)
300 {
301 bHelpOpen = TRUE;
302 }
303 }
304 }
305 break;
306 }
307 }
308 }
309
310 return FALSE;
311}
INT AllocAndLoadString(OUT LPTSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:59
static VOID FreeMemory(PCREATE_DATA Data)
Definition: create.c:134
static BOOL GetDataFromDialog(PCREATE_DATA Data)
Definition: create.c:112
static LPWSTR GetStringFromDialog(PCREATE_DATA Data, UINT id)
Definition: create.c:82
struct _CREATE_DATA * PCREATE_DATA
struct _CREATE_DATA CREATE_DATA
static BOOL DoCreate(PCREATE_DATA Data)
Definition: create.c:26
INT_PTR CALLBACK CreateHelpDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: create.c:163
static BOOL bHelpOpen
Definition: create.c:23
INT_PTR CALLBACK CreateDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: create.c:218
VOID DisplayString(LPWSTR Msg)
Definition: misc.c:211
HANDLE ProcessHeap
Definition: servman.c:15
BOOL SetServiceDescription(LPWSTR lpServiceName, LPWSTR lpDescription)
Definition: query.c:210
#define IDC_CREATE_DISPNAME
Definition: resource.h:183
#define IDS_HELP_OPTIONS
Definition: resource.h:190
#define IDC_CREATE_SERVNAME
Definition: resource.h:182
#define IDS_CREATE_SUCCESS
Definition: resource.h:191
#define ID_CREATE_HELP
Definition: resource.h:187
#define IDC_CREATE_DESC
Definition: resource.h:185
#define IDD_DLG_HELP_OPTIONS
Definition: resource.h:188
#define IDI_SM_ICON
Definition: resource.h:64
#define IDC_CREATE_HELP
Definition: resource.h:189
#define IDC_CREATE_OPTIONS
Definition: resource.h:186
#define IDC_CREATE_PATH
Definition: resource.h:184
HINSTANCE hInstance
Definition: charmap.c:19
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned int BOOL
Definition: ntddk_ex.h:94
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
static HICON
Definition: imagelist.c:84
HICON hIcon
Definition: msconfig.c:44
unsigned int UINT
Definition: ndis.h:50
#define LOWORD(l)
Definition: pedump.c:82
SC_HANDLE hSCManager
Definition: sc.c:12
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2068
SC_HANDLE WINAPI CreateServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, LPCWSTR lpDisplayName, DWORD dwDesiredAccess, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCWSTR lpBinaryPathName, LPCWSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCWSTR lpDependencies, LPCWSTR lpServiceStartName, LPCWSTR lpPassword)
Definition: scm.c:812
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
LPWSTR BinPath
Definition: create.c:17
LPWSTR Options
Definition: create.c:19
LPWSTR Description
Definition: create.c:18
HWND hSelf
Definition: create.c:14
LPWSTR DisplayName
Definition: create.c:16
LPWSTR ServiceName
Definition: create.c:15
Definition: tftpd.h:60
#define ICON_SMALL
Definition: tnclass.cpp:48
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1412
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
#define SC_MANAGER_ALL_ACCESS
Definition: winsvc.h:13
#define IDCANCEL
Definition: winuser.h:831
#define IMAGE_ICON
Definition: winuser.h:212
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define WM_COMMAND
Definition: winuser.h:1740
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE hInst, _In_ LPCWSTR name, _In_ UINT type, _In_ int cx, _In_ int cy, _In_ UINT fuLoad)
Definition: cursoricon.c:2234
#define CreateDialog
Definition: winuser.h:5749
#define WM_INITDIALOG
Definition: winuser.h:1739
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDOK
Definition: winuser.h:830
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
#define SendMessage
Definition: winuser.h:5843
int WINAPI GetWindowTextLengthW(_In_ HWND)
#define LoadImage
Definition: winuser.h:5815
BOOL WINAPI DestroyWindow(_In_ HWND)
#define MAKEINTRESOURCE
Definition: winuser.h:591
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2084
#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
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184