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>
13 TV1_GetDependants(PSERVICEPROPSHEET pDlgInfo
,
16 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
21 /* Get the info for this service */
22 if (!QueryServiceConfig(hService
,
26 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
28 lpServiceConfig
= HeapAlloc(ProcessHeap
,
33 if (QueryServiceConfig(hService
,
38 /* Does this service have any dependencies? */
39 if (lpServiceConfig
->lpDependencies
&&
40 *lpServiceConfig
->lpDependencies
!= '\0')
42 lpStr
= lpServiceConfig
->lpDependencies
;
45 /* Work out how many bytes we need to hold the list */
50 if (!*lpStr
&& !*(lpStr
+ 1))
59 /* Allocate and copy the list */
60 bytes
*= sizeof(TCHAR
);
61 lpStr
= HeapAlloc(ProcessHeap
,
67 lpServiceConfig
->lpDependencies
,
73 HeapFree(GetProcessHeap(),
83 TV1_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo
,
89 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
95 hSCManager
= OpenSCManager(NULL
,
97 SC_MANAGER_ALL_ACCESS
);
100 hService
= OpenService(hSCManager
,
102 SERVICE_QUERY_STATUS
| SERVICE_ENUMERATE_DEPENDENTS
| SERVICE_QUERY_CONFIG
);
105 /* Get a list of service dependents */
106 lpDependants
= TV1_GetDependants(pDlgInfo
, hService
);
109 lpStr
= lpDependants
;
111 /* Make sure this isn't the end of the list */
114 /* Get the info for this service */
115 lpServiceConfig
= GetServiceConfig(lpStr
);
118 /* Does this item need a +/- box? */
119 if (lpServiceConfig
->lpDependencies
&&
120 *lpServiceConfig
->lpDependencies
!= '\0')
126 bHasChildren
= FALSE
;
130 AddItemToTreeView(pDlgInfo
->hDependsTreeView1
,
132 lpServiceConfig
->lpDisplayName
,
134 lpServiceConfig
->dwServiceType
,
137 HeapFree(GetProcessHeap(),
142 /* Move to the end of the string */
147 HeapFree(GetProcessHeap(),
153 /* If there is no parent, set the tree to 'no dependencies' */
156 /* Load the 'No dependencies' string */
157 AllocAndLoadString(&lpNoDepends
, hInstance
, IDS_NO_DEPENDS
);
159 AddItemToTreeView(pDlgInfo
->hDependsTreeView1
,
166 LocalFree(lpNoDepends
);
168 /* Disable the window */
169 EnableWindow(pDlgInfo
->hDependsTreeView1
, FALSE
);
173 CloseServiceHandle(hService
);
176 CloseServiceHandle(hSCManager
);
181 TV1_Initialize(PSERVICEPROPSHEET pDlgInfo
,
182 LPTSTR lpServiceName
)
186 /* Accociate the imagelist with TV1 */
187 pDlgInfo
->hDependsTreeView1
= GetDlgItem(pDlgInfo
->hDependsWnd
, IDC_DEPEND_TREE1
);
188 if (!pDlgInfo
->hDependsTreeView1
)
190 ImageList_Destroy(pDlgInfo
->hDependsImageList
);
191 pDlgInfo
->hDependsImageList
= NULL
;
194 (void)TreeView_SetImageList(pDlgInfo
->hDependsTreeView1
,
195 pDlgInfo
->hDependsImageList
,
198 /* Set the first items in the control */
199 TV1_AddDependantsToTree(pDlgInfo
, NULL
, lpServiceName
);