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-2010 Ged Murphy <gedmurphy@reactos.org>
13 AddServiceToList(LPWSTR
*lpServiceList
,
14 LPWSTR lpServiceToAdd
)
16 LPWSTR lpNewList
= NULL
;
21 dwToAddSize
= wcslen(lpServiceToAdd
) + 1;
23 /* Is this is the first in the list? */
26 /* Add another char for double null */
29 lpNewList
= HeapAlloc(GetProcessHeap(),
31 dwToAddSize
* sizeof(WCHAR
));
34 /* Copy the service name */
39 /* Add the double null char */
40 lpNewList
[dwToAddSize
- 1] = L
'\0';
48 /* Get the list size */
51 /* Break when we hit the double null */
52 if (*ptr
== L
'\0' && *(ptr
+ 1) == L
'\0')
60 /* Add another char for double null */
63 /* Extend the list size */
64 lpNewList
= HeapReAlloc(GetProcessHeap(),
67 (dwCurSize
+ dwToAddSize
) * sizeof(WCHAR
));
70 /* Copy the service name */
71 wcscpy_s(&lpNewList
[dwCurSize
- 1],
75 /* Add the double null char */
76 lpNewList
[dwCurSize
+ dwToAddSize
- 1] = L
'\0';
84 BuildListOfServicesToStop(LPWSTR
*lpServiceList
,
87 LPENUM_SERVICE_STATUS lpServiceStatus
;
91 /* Get a list of service dependents */
92 lpServiceStatus
= TV2_GetDependants(lpServiceName
, &dwCount
);
95 for (i
= 0; i
< dwCount
; i
++)
97 /* Does this service need stopping? */
98 if (lpServiceStatus
[i
].ServiceStatus
.dwCurrentState
!= SERVICE_STOPPED
&&
99 lpServiceStatus
[i
].ServiceStatus
.dwCurrentState
!= SERVICE_STOP_PENDING
)
101 /* Does this service have any dependents? */
102 if (TV2_HasDependantServices(lpServiceStatus
[i
].lpServiceName
))
104 /* recall this function with the dependent */
105 BuildListOfServicesToStop(lpServiceList
, lpServiceStatus
[i
].lpServiceName
);
108 /* Add the service to the list */
109 *lpServiceList
= AddServiceToList(lpServiceList
, lpServiceStatus
[i
].lpServiceName
);
116 HeapFree(GetProcessHeap(),
125 GetListOfServicesToStop(LPWSTR lpServiceName
)
127 LPWSTR lpServiceList
= NULL
;
129 /* Call recursive function to get our list */
130 if (BuildListOfServicesToStop(&lpServiceList
, lpServiceName
))
131 return lpServiceList
;
137 AddServiceNamesToStop(HWND hServiceListBox
,
138 LPWSTR lpServiceList
)
140 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
143 lpStr
= lpServiceList
;
145 /* Loop through all the services in the list */
148 /* Break when we hit the double null */
149 if (*lpStr
== L
'\0' && *(lpStr
+ 1) == L
'\0')
152 /* If this isn't our first time in the loop we'll
153 have been left on a null char */
157 /* Get the service's display name */
158 lpServiceConfig
= GetServiceConfig(lpStr
);
161 /* Add the service to the listbox */
162 SendMessageW(hServiceListBox
,
165 (LPARAM
)lpServiceConfig
->lpDisplayName
);
168 /* Move onto the next string */
169 while (*lpStr
!= L
'\0')
175 DoInitDependsDialog(PMAIN_WND_INFO pInfo
,
178 HWND hServiceListBox
;
179 LPWSTR lpPartialStr
, lpStr
;
186 /* Tag the info to the window */
187 SetWindowLongPtrW(hDlg
,
191 /* Load the icon for the window */
192 hIcon
= (HICON
)LoadImageW(hInstance
,
193 MAKEINTRESOURCE(IDI_SM_ICON
),
195 GetSystemMetrics(SM_CXSMICON
),
196 GetSystemMetrics(SM_CXSMICON
),
208 /* Load the stop depends note */
209 if (AllocAndLoadString(&lpPartialStr
,
213 /* Get the length required */
214 fullLen
= wcslen(lpPartialStr
) + wcslen(pInfo
->pCurrentService
->lpDisplayName
) + 1;
216 lpStr
= HeapAlloc(ProcessHeap
,
218 fullLen
* sizeof(WCHAR
));
221 /* Add the service name to the depends note */
225 pInfo
->pCurrentService
->lpDisplayName
);
227 /* Add the string to the dialog */
228 SendDlgItemMessageW(hDlg
,
234 HeapFree(ProcessHeap
,
241 HeapFree(ProcessHeap
,
246 /* Display the list of services which need stopping */
247 hServiceListBox
= GetDlgItem(hDlg
,
248 IDC_STOP_DEPENDS_LB
);
251 AddServiceNamesToStop(hServiceListBox
,
252 (LPWSTR
)pInfo
->pTag
);
260 StopDependsDialogProc(HWND hDlg
,
265 PMAIN_WND_INFO pInfo
= NULL
;
267 /* Get the window context */
268 pInfo
= (PMAIN_WND_INFO
)GetWindowLongPtrW(hDlg
,
270 if (pInfo
== NULL
&& message
!= WM_INITDIALOG
)
281 pInfo
= (PMAIN_WND_INFO
)lParam
;
284 bRet
= DoInitDependsDialog(pInfo
, hDlg
);
292 switch (LOWORD(wParam
))