2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/tv2_dependencies.c
5 * PURPOSE: Helper functions for service dependents
6 * COPYRIGHT: Copyright 2009 Ged Murphy <gedmurphy@reactos.org>
13 TV2_HasDependantServices(LPWSTR lpServiceName
)
17 DWORD dwBytesNeeded
, dwCount
;
20 hSCManager
= OpenSCManager(NULL
,
22 SC_MANAGER_ALL_ACCESS
);
25 hService
= OpenService(hSCManager
,
27 SERVICE_QUERY_STATUS
| SERVICE_ENUMERATE_DEPENDENTS
);
30 /* Does this have any dependencies? */
31 if (!EnumDependentServices(hService
,
38 if (GetLastError() == ERROR_MORE_DATA
)
40 /* It does, return TRUE */
46 CloseServiceHandle(hSCManager
);
53 TV2_GetDependants(LPWSTR lpServiceName
,
58 LPENUM_SERVICE_STATUSW lpDependencies
= NULL
;
62 /* Set the first items in each tree view */
63 hSCManager
= OpenSCManagerW(NULL
,
65 SC_MANAGER_ALL_ACCESS
);
68 hService
= OpenServiceW(hSCManager
,
70 SERVICE_QUERY_STATUS
| SERVICE_ENUMERATE_DEPENDENTS
| SERVICE_QUERY_CONFIG
);
73 /* Does this have any dependencies? */
74 if (!EnumDependentServicesW(hService
,
80 GetLastError() == ERROR_MORE_DATA
)
82 lpDependencies
= (LPENUM_SERVICE_STATUSW
)HeapAlloc(GetProcessHeap(),
87 /* Get the list of dependents */
88 if (EnumDependentServicesW(hService
,
100 HeapFree(ProcessHeap
,
104 lpDependencies
= NULL
;
109 CloseServiceHandle(hService
);
112 CloseServiceHandle(hSCManager
);
115 return lpDependencies
;
119 TV2_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo
,
121 LPTSTR lpServiceName
)
124 LPENUM_SERVICE_STATUSW lpServiceStatus
;
129 /* Get a list of service dependents */
130 lpServiceStatus
= TV2_GetDependants(lpServiceName
, &count
);
133 for (i
= 0; i
< count
; i
++)
135 /* Does this item need a +/- box? */
136 bHasChildren
= TV2_HasDependantServices(lpServiceStatus
[i
].lpServiceName
);
139 AddItemToTreeView(pDlgInfo
->hDependsTreeView2
,
141 lpServiceStatus
[i
].lpDisplayName
,
142 lpServiceStatus
[i
].lpServiceName
,
143 lpServiceStatus
[i
].ServiceStatus
.dwServiceType
,
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
->hDependsTreeView2
,
166 HeapFree(ProcessHeap
,
170 /* Disable the window */
171 EnableWindow(pDlgInfo
->hDependsTreeView2
, FALSE
);
177 TV2_Initialize(PSERVICEPROPSHEET pDlgInfo
,
178 LPTSTR lpServiceName
)
182 /* Accociate the imagelist with TV2 */
183 pDlgInfo
->hDependsTreeView2
= GetDlgItem(pDlgInfo
->hDependsWnd
, IDC_DEPEND_TREE2
);
184 if (!pDlgInfo
->hDependsTreeView2
)
186 ImageList_Destroy(pDlgInfo
->hDependsImageList
);
187 pDlgInfo
->hDependsImageList
= NULL
;
190 (void)TreeView_SetImageList(pDlgInfo
->hDependsTreeView2
,
191 pDlgInfo
->hDependsImageList
,
194 /* Set the first items in the control */
195 TV2_AddDependantsToTree(pDlgInfo
, NULL
, lpServiceName
);