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>
14 TV2_HasDependantServices(LPWSTR lpServiceName
)
18 DWORD dwBytesNeeded
, dwCount
;
21 hSCManager
= OpenSCManager(NULL
,
23 SC_MANAGER_ALL_ACCESS
);
26 hService
= OpenService(hSCManager
,
28 SERVICE_QUERY_STATUS
| SERVICE_ENUMERATE_DEPENDENTS
);
31 /* Does this have any dependencies? */
32 if (!EnumDependentServices(hService
,
39 if (GetLastError() == ERROR_MORE_DATA
)
41 /* It does, return TRUE */
47 CloseServiceHandle(hSCManager
);
55 TV2_GetDependants(LPWSTR lpServiceName
,
60 LPENUM_SERVICE_STATUSW lpDependencies
= NULL
;
64 /* Set the first items in each tree view */
65 hSCManager
= OpenSCManagerW(NULL
,
67 SC_MANAGER_ALL_ACCESS
);
70 hService
= OpenServiceW(hSCManager
,
72 SERVICE_QUERY_STATUS
| SERVICE_ENUMERATE_DEPENDENTS
| SERVICE_QUERY_CONFIG
);
75 /* Does this have any dependencies? */
76 if (!EnumDependentServicesW(hService
,
82 GetLastError() == ERROR_MORE_DATA
)
84 lpDependencies
= (LPENUM_SERVICE_STATUSW
)HeapAlloc(GetProcessHeap(),
89 /* Get the list of dependents */
90 if (EnumDependentServicesW(hService
,
102 HeapFree(ProcessHeap
,
106 lpDependencies
= NULL
;
111 CloseServiceHandle(hService
);
114 CloseServiceHandle(hSCManager
);
117 return lpDependencies
;
122 TV2_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo
,
124 LPTSTR lpServiceName
)
127 LPENUM_SERVICE_STATUSW lpServiceStatus
;
132 /* Get a list of service dependents */
133 lpServiceStatus
= TV2_GetDependants(lpServiceName
, &count
);
136 for (i
= 0; i
< count
; i
++)
138 /* Does this item need a +/- box? */
139 bHasChildren
= TV2_HasDependantServices(lpServiceStatus
[i
].lpServiceName
);
142 AddItemToTreeView(pDlgInfo
->hDependsTreeView2
,
144 lpServiceStatus
[i
].lpDisplayName
,
145 lpServiceStatus
[i
].lpServiceName
,
146 lpServiceStatus
[i
].ServiceStatus
.dwServiceType
,
150 HeapFree(GetProcessHeap(),
156 /* If there is no parent, set the tree to 'no dependencies' */
159 /* Load the 'No dependencies' string */
160 AllocAndLoadString(&lpNoDepends
, hInstance
, IDS_NO_DEPENDS
);
162 AddItemToTreeView(pDlgInfo
->hDependsTreeView2
,
169 HeapFree(ProcessHeap
,
173 /* Disable the window */
174 EnableWindow(pDlgInfo
->hDependsTreeView2
, FALSE
);
180 TV2_Initialize(PSERVICEPROPSHEET pDlgInfo
,
181 LPTSTR lpServiceName
)
185 /* Accociate the imagelist with TV2 */
186 pDlgInfo
->hDependsTreeView2
= GetDlgItem(pDlgInfo
->hDependsWnd
, IDC_DEPEND_TREE2
);
187 if (!pDlgInfo
->hDependsTreeView2
)
189 ImageList_Destroy(pDlgInfo
->hDependsImageList
);
190 pDlgInfo
->hDependsImageList
= NULL
;
193 (void)TreeView_SetImageList(pDlgInfo
->hDependsTreeView2
,
194 pDlgInfo
->hDependsImageList
,
197 /* Set the first items in the control */
198 TV2_AddDependantsToTree(pDlgInfo
, NULL
, lpServiceName
);