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>
12 typedef struct _STOP_DATA
18 } STOP_DATA
, *PSTOP_DATA
;
21 AddServiceToList(LPWSTR
*lpServiceList
,
22 LPWSTR lpServiceToAdd
)
24 LPWSTR lpNewList
= NULL
;
29 dwToAddSize
= wcslen(lpServiceToAdd
) + 1;
31 /* Is this is the first in the list? */
34 /* Add another char for double null */
37 lpNewList
= HeapAlloc(GetProcessHeap(),
39 dwToAddSize
* sizeof(WCHAR
));
42 /* Copy the service name */
43 StringCchCopy(lpNewList
,
47 /* Add the double null char */
48 lpNewList
[dwToAddSize
- 1] = L
'\0';
56 /* Get the list size */
59 /* Break when we hit the double null */
60 if (*ptr
== L
'\0' && *(ptr
+ 1) == L
'\0')
68 /* Add another char for double null */
71 /* Extend the list size */
72 lpNewList
= HeapReAlloc(GetProcessHeap(),
75 (dwCurSize
+ dwToAddSize
) * sizeof(WCHAR
));
78 /* Copy the service name */
79 StringCchCopy(&lpNewList
[dwCurSize
- 1],
83 /* Add the double null char */
84 lpNewList
[dwCurSize
+ dwToAddSize
- 1] = L
'\0';
92 BuildListOfServicesToStop(LPWSTR
*lpServiceList
,
95 LPENUM_SERVICE_STATUS lpServiceStatus
;
99 /* Get a list of service dependents */
100 lpServiceStatus
= TV2_GetDependants(lpServiceName
, &dwCount
);
103 for (i
= 0; i
< dwCount
; i
++)
105 /* Does this service need stopping? */
106 if (lpServiceStatus
[i
].ServiceStatus
.dwCurrentState
!= SERVICE_STOPPED
&&
107 lpServiceStatus
[i
].ServiceStatus
.dwCurrentState
!= SERVICE_STOP_PENDING
)
109 /* Add the service to the list */
110 *lpServiceList
= AddServiceToList(lpServiceList
, lpServiceStatus
[i
].lpServiceName
);
117 HeapFree(GetProcessHeap(),
126 GetListOfServicesToStop(LPWSTR lpServiceName
)
128 LPWSTR lpServiceList
= NULL
;
130 /* Call recursive function to get our list */
131 if (BuildListOfServicesToStop(&lpServiceList
, lpServiceName
))
132 return lpServiceList
;
138 AddServiceNamesToStop(HWND hServiceListBox
,
139 LPWSTR lpServiceList
)
141 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
144 lpStr
= lpServiceList
;
146 /* Loop through all the services in the list */
149 /* Break when we hit the double null */
150 if (*lpStr
== L
'\0' && *(lpStr
+ 1) == L
'\0')
153 /* If this isn't our first time in the loop we'll
154 have been left on a null char */
158 /* Get the service's display name */
159 lpServiceConfig
= GetServiceConfig(lpStr
);
162 /* Add the service to the listbox */
163 SendMessageW(hServiceListBox
,
166 (LPARAM
)lpServiceConfig
->lpDisplayName
);
168 HeapFree(GetProcessHeap(), 0, lpServiceConfig
);
171 /* Move onto the next string */
172 while (*lpStr
!= L
'\0')
178 InitDialog(HWND hDlg
,
184 HWND hServiceListBox
;
185 LPWSTR lpPartialStr
, lpStr
;
190 StopData
= (PSTOP_DATA
)lParam
;
193 /* Load the icon for the window */
194 hIcon
= (HICON
)LoadImageW(hInstance
,
195 MAKEINTRESOURCE(IDI_SM_ICON
),
197 GetSystemMetrics(SM_CXSMICON
),
198 GetSystemMetrics(SM_CXSMICON
),
210 /* Load the stop depends note */
211 if (AllocAndLoadString(&lpPartialStr
,
215 /* Get the length required */
216 fullLen
= wcslen(lpPartialStr
) + wcslen(StopData
->DisplayName
) + 1;
218 lpStr
= HeapAlloc(ProcessHeap
,
220 fullLen
* sizeof(WCHAR
));
223 /* Add the service name to the depends note */
227 StopData
->DisplayName
);
229 /* Add the string to the dialog */
230 SendDlgItemMessageW(hDlg
,
236 HeapFree(ProcessHeap
,
243 LocalFree(lpPartialStr
);
246 /* Display the list of services which need stopping */
247 hServiceListBox
= GetDlgItem(hDlg
, IDC_STOP_DEPENDS_LB
);
250 AddServiceNamesToStop(hServiceListBox
,
251 (LPWSTR
)StopData
->ServiceList
);
258 StopDependsDialogProc(HWND hDlg
,
268 return InitDialog(hDlg
,
276 switch (LOWORD(wParam
))
293 CreateStopDependsDialog(HWND hParent
,
301 StopData
.ServiceName
= ServiceName
;
302 StopData
.DisplayName
= DisplayName
;
303 StopData
.ServiceList
= ServiceList
;
305 Result
= DialogBoxParamW(hInstance
,
306 MAKEINTRESOURCEW(IDD_DLG_DEPEND_STOP
),
308 StopDependsDialogProc
,