2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/tv1_dependencies.c
5 * PURPOSE: Helper functions for service dependents
6 * COPYRIGHT: Copyright 2009 Ged Murphy <gedmurphy@reactos.org>
14 TV1_GetDependants(PSERVICEPROPSHEET pDlgInfo
,
17 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
22 /* Get the info for this service */
23 if (!QueryServiceConfig(hService
,
27 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
29 lpServiceConfig
= HeapAlloc(ProcessHeap
,
34 if (QueryServiceConfig(hService
,
39 /* Does this service have any dependencies? */
40 if (lpServiceConfig
->lpDependencies
&&
41 *lpServiceConfig
->lpDependencies
!= '\0')
43 lpStr
= lpServiceConfig
->lpDependencies
;
46 /* Work out how many bytes we need to hold the list */
51 if (!*lpStr
&& !*(lpStr
+ 1))
60 /* Allocate and copy the list */
61 bytes
*= sizeof(TCHAR
);
62 lpStr
= HeapAlloc(ProcessHeap
,
68 lpServiceConfig
->lpDependencies
,
74 HeapFree(GetProcessHeap(),
84 TV1_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo
,
90 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
96 hSCManager
= OpenSCManager(NULL
,
98 SC_MANAGER_ALL_ACCESS
);
101 hService
= OpenService(hSCManager
,
103 SERVICE_QUERY_STATUS
| SERVICE_ENUMERATE_DEPENDENTS
| SERVICE_QUERY_CONFIG
);
106 /* Get a list of service dependents */
107 lpDependants
= TV1_GetDependants(pDlgInfo
, hService
);
110 lpStr
= lpDependants
;
112 /* Make sure this isn't the end of the list */
115 /* Get the info for this service */
116 lpServiceConfig
= GetServiceConfig(lpStr
);
119 /* Does this item need a +/- box? */
120 if (lpServiceConfig
->lpDependencies
&&
121 *lpServiceConfig
->lpDependencies
!= '\0')
127 bHasChildren
= FALSE
;
131 AddItemToTreeView(pDlgInfo
->hDependsTreeView1
,
133 lpServiceConfig
->lpDisplayName
,
135 lpServiceConfig
->dwServiceType
,
138 HeapFree(GetProcessHeap(),
143 /* Move to the end of the string */
148 HeapFree(GetProcessHeap(),
154 /* If there is no parent, set the tree to 'no dependencies' */
157 /* Load the 'No dependencies' string */
158 AllocAndLoadString(&lpNoDepends
, hInstance
, IDS_NO_DEPENDS
);
160 AddItemToTreeView(pDlgInfo
->hDependsTreeView1
,
167 HeapFree(ProcessHeap
,
171 /* Disable the window */
172 EnableWindow(pDlgInfo
->hDependsTreeView1
, FALSE
);
176 CloseServiceHandle(hService
);
179 CloseServiceHandle(hSCManager
);
185 TV1_Initialize(PSERVICEPROPSHEET pDlgInfo
,
186 LPTSTR lpServiceName
)
190 /* Accociate the imagelist with TV1 */
191 pDlgInfo
->hDependsTreeView1
= GetDlgItem(pDlgInfo
->hDependsWnd
, IDC_DEPEND_TREE1
);
192 if (!pDlgInfo
->hDependsTreeView1
)
194 ImageList_Destroy(pDlgInfo
->hDependsImageList
);
195 pDlgInfo
->hDependsImageList
= NULL
;
198 (void)TreeView_SetImageList(pDlgInfo
->hDependsTreeView1
,
199 pDlgInfo
->hDependsImageList
,
202 /* Set the first items in the control */
203 TV1_AddDependantsToTree(pDlgInfo
, NULL
, lpServiceName
);