ReactOS 0.4.16-dev-320-g3bd9ddc
stop_dependencies.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/stop_dependencies.c
5 * PURPOSE: Routines related to stopping dependent services
6 * COPYRIGHT: Copyright 2006-2015 Ged Murphy <gedmurphy@reactos.org>
7 *
8 */
9
10#include "precomp.h"
11
12typedef struct _STOP_DATA
13{
17
19
20static LPWSTR
21AddServiceToList(LPWSTR *lpServiceList,
22 LPWSTR lpServiceToAdd)
23{
24 LPWSTR lpNewList = NULL;
25 LPWSTR ptr;
26 DWORD dwToAddSize;
27 DWORD dwCurSize;
28
29 dwToAddSize = wcslen(lpServiceToAdd) + 1;
30
31 /* Is this is the first in the list? */
32 if (!*lpServiceList)
33 {
34 /* Add another char for double null */
35 dwToAddSize++;
36
37 lpNewList = HeapAlloc(GetProcessHeap(),
38 0,
39 dwToAddSize * sizeof(WCHAR));
40 if (lpNewList)
41 {
42 /* Copy the service name */
43 StringCchCopy(lpNewList,
44 dwToAddSize,
45 lpServiceToAdd);
46
47 /* Add the double null char */
48 lpNewList[dwToAddSize - 1] = L'\0';
49 }
50 }
51 else
52 {
53 ptr = *lpServiceList;
54 dwCurSize = 0;
55
56 /* Get the list size */
57 for (;;)
58 {
59 /* Break when we hit the double null */
60 if (*ptr == L'\0' && *(ptr + 1) == L'\0')
61 break;
62
63 ptr++;
64 dwCurSize++;
65 }
66 dwCurSize++;
67
68 /* Add another char for double null */
69 dwCurSize++;
70
71 /* Extend the list size */
72 lpNewList = HeapReAlloc(GetProcessHeap(),
73 0,
74 *lpServiceList,
75 (dwCurSize + dwToAddSize) * sizeof(WCHAR));
76 if (lpNewList)
77 {
78 /* Copy the service name */
79 StringCchCopy(&lpNewList[dwCurSize - 1],
80 dwToAddSize,
81 lpServiceToAdd);
82
83 /* Add the double null char */
84 lpNewList[dwCurSize + dwToAddSize - 1] = L'\0';
85 }
86 }
87
88 return lpNewList;
89}
90
91static BOOL
93 LPWSTR lpServiceName)
94{
95 LPENUM_SERVICE_STATUS lpServiceStatus;
96 DWORD dwCount, i;
97 BOOL bRet = FALSE;
98
99 /* Get a list of service dependents */
100 lpServiceStatus = TV2_GetDependants(lpServiceName, &dwCount);
101 if (lpServiceStatus)
102 {
103 for (i = 0; i < dwCount; i++)
104 {
105 /* Does this service need stopping? */
106 if (lpServiceStatus[i].ServiceStatus.dwCurrentState != SERVICE_STOPPED &&
108 {
109 /* Add the service to the list */
110 *lpServiceList = AddServiceToList(lpServiceList, lpServiceStatus[i].lpServiceName);
111
112 /* We've got one */
113 bRet = TRUE;
114 }
115 }
116
118 0,
119 lpServiceStatus);
120 }
121
122 return bRet;
123}
124
125LPWSTR
127{
128 LPWSTR lpServiceList = NULL;
129
130 /* Call recursive function to get our list */
131 if (BuildListOfServicesToStop(&lpServiceList, lpServiceName))
132 return lpServiceList;
133 else
134 return NULL;
135}
136
137static VOID
139 LPWSTR lpServiceList)
140{
141 LPQUERY_SERVICE_CONFIG lpServiceConfig;
142 LPWSTR lpStr;
143
144 lpStr = lpServiceList;
145
146 /* Loop through all the services in the list */
147 for (;;)
148 {
149 /* Break when we hit the double null */
150 if (*lpStr == L'\0' && *(lpStr + 1) == L'\0')
151 break;
152
153 /* If this isn't our first time in the loop we'll
154 have been left on a null char */
155 if (*lpStr == L'\0')
156 lpStr++;
157
158 /* Get the service's display name */
159 lpServiceConfig = GetServiceConfig(lpStr);
160 if (lpServiceConfig)
161 {
162 /* Add the service to the listbox */
163 SendMessageW(hServiceListBox,
165 0,
166 (LPARAM)lpServiceConfig->lpDisplayName);
167
168 HeapFree(GetProcessHeap(), 0, lpServiceConfig);
169 }
170
171 /* Move onto the next string */
172 while (*lpStr != L'\0')
173 lpStr++;
174 }
175}
176
177static BOOL
182{
183 PSTOP_DATA StopData;
184 HWND hServiceListBox;
185 LPWSTR lpPartialStr, lpStr;
186 DWORD fullLen;
187 HICON hIcon = NULL;
188 BOOL bRet = FALSE;
189
190 StopData = (PSTOP_DATA)lParam;
191
192
193 /* Load the icon for the window */
199 0);
200 if (hIcon)
201 {
202 /* Set it */
203 SendMessageW(hDlg,
204 WM_SETICON,
206 (LPARAM)hIcon);
208 }
209
210 /* Load the stop depends note */
211 if (AllocAndLoadString(&lpPartialStr,
212 hInstance,
214 {
215 /* Get the length required */
216 fullLen = wcslen(lpPartialStr) + wcslen(StopData->DisplayName) + 1;
217
218 lpStr = HeapAlloc(ProcessHeap,
219 0,
220 fullLen * sizeof(WCHAR));
221 if (lpStr)
222 {
223 /* Add the service name to the depends note */
224 _snwprintf(lpStr,
225 fullLen,
226 lpPartialStr,
227 StopData->DisplayName);
228
229 /* Add the string to the dialog */
233 0,
234 (LPARAM)lpStr);
235
237 0,
238 lpStr);
239
240 bRet = TRUE;
241 }
242
243 LocalFree(lpPartialStr);
244 }
245
246 /* Display the list of services which need stopping */
247 hServiceListBox = GetDlgItem(hDlg, IDC_STOP_DEPENDS_LB);
248 if (hServiceListBox)
249 {
250 AddServiceNamesToStop(hServiceListBox,
251 (LPWSTR)StopData->ServiceList);
252 }
253
254 return bRet;
255}
256
262{
263
264 switch (Message)
265 {
266 case WM_INITDIALOG:
267 {
268 return InitDialog(hDlg,
269 Message,
270 wParam,
271 lParam);
272 }
273
274 case WM_COMMAND:
275 {
276 switch (LOWORD(wParam))
277 {
278 case IDOK:
279 case IDCANCEL:
280 {
281 EndDialog(hDlg,
282 LOWORD(wParam));
283 return TRUE;
284 }
285 }
286 }
287 }
288
289 return FALSE;
290}
291
292BOOL
295 LPWSTR DisplayName,
296 LPWSTR ServiceList)
297{
298 STOP_DATA StopData;
300
301 StopData.ServiceName = ServiceName;
302 StopData.DisplayName = DisplayName;
303 StopData.ServiceList = ServiceList;
304
307 hParent,
309 (LPARAM)&StopData);
310 if (Result == IDOK)
311 return TRUE;
312
313 return FALSE;
314}
INT AllocAndLoadString(OUT LPTSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:59
LPQUERY_SERVICE_CONFIG GetServiceConfig(LPWSTR lpServiceName)
Definition: query.c:29
HANDLE ProcessHeap
Definition: servman.c:15
#define IDS_STOP_DEPENDS
Definition: resource.h:215
#define IDD_DLG_DEPEND_STOP
Definition: resource.h:213
#define IDC_STOP_DEPENDS
Definition: resource.h:214
#define IDI_SM_ICON
Definition: resource.h:64
#define IDC_STOP_DEPENDS_LB
Definition: resource.h:216
static WCHAR ServiceName[]
Definition: browser.c:19
static SERVICE_STATUS ServiceStatus
Definition: browser.c:22
HINSTANCE hInstance
Definition: charmap.c:19
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
LPENUM_SERVICE_STATUS TV2_GetDependants(LPWSTR lpServiceName, LPDWORD lpdwCount)
#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 HeapReAlloc
Definition: compat.h:734
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
static const WCHAR Message[]
Definition: register.c:74
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
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
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
static PVOID ptr
Definition: dispmode.c:27
static HICON
Definition: imagelist.c:80
HICON hIcon
Definition: msconfig.c:44
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
LPWSTR GetListOfServicesToStop(LPWSTR lpServiceName)
static LPWSTR AddServiceToList(LPWSTR *lpServiceList, LPWSTR lpServiceToAdd)
static BOOL InitDialog(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
static VOID AddServiceNamesToStop(HWND hServiceListBox, LPWSTR lpServiceList)
BOOL CreateStopDependsDialog(HWND hParent, LPWSTR ServiceName, LPWSTR DisplayName, LPWSTR ServiceList)
struct _STOP_DATA * PSTOP_DATA
struct _STOP_DATA STOP_DATA
INT_PTR CALLBACK StopDependsDialogProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
static BOOL BuildListOfServicesToStop(LPWSTR *lpServiceList, LPWSTR lpServiceName)
#define StringCchCopy
Definition: strsafe.h:139
SERVICE_STATUS ServiceStatus
Definition: winsvc.h:127
DWORD dwCurrentState
Definition: winsvc.h:100
LPWSTR ServiceName
LPWSTR DisplayName
LPWSTR ServiceList
#define ICON_SMALL
Definition: tnclass.cpp:48
int32_t INT_PTR
Definition: typedefs.h:64
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define IDCANCEL
Definition: winuser.h:834
#define IMAGE_ICON
Definition: winuser.h:212
#define WM_COMMAND
Definition: winuser.h:1743
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:2255
#define WM_INITDIALOG
Definition: winuser.h:1742
#define LB_ADDSTRING
Definition: winuser.h:2034
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDOK
Definition: winuser.h:833
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_SETTEXT
Definition: winuser.h:1620
#define SM_CXSMICON
Definition: winuser.h:1015
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define MAKEINTRESOURCE
Definition: winuser.h:591
int WINAPI GetSystemMetrics(_In_ int)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2105
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184