ReactOS 0.4.15-dev-7942-gd23573b
dependencies_tv2.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/dependencies_tv2.c
5 * PURPOSE: Helper functions for service dependents
6 * COPYRIGHT: Copyright 2009 Ged Murphy <gedmurphy@reactos.org>
7 *
8 */
9
10#include "precomp.h"
11
12BOOL
14{
16 HANDLE hService;
17 DWORD dwBytesNeeded, dwCount;
18 BOOL bRet = FALSE;
19
21 NULL,
23 if (hSCManager)
24 {
25 hService = OpenServiceW(hSCManager,
26 lpServiceName,
28 if (hService)
29 {
30 /* Does this have any dependencies? */
31 if (!EnumDependentServices(hService,
33 NULL,
34 0,
35 &dwBytesNeeded,
36 &dwCount))
37 {
39 {
40 /* It does, return TRUE */
41 bRet = TRUE;
42 }
43 }
44
45 CloseServiceHandle(hService);
46 }
47
49 }
50
51 return bRet;
52}
53
56 LPDWORD lpdwCount)
57{
58 SC_HANDLE hSCManager;
59 SC_HANDLE hService;
60 LPENUM_SERVICE_STATUSW lpDependencies = NULL;
61 DWORD dwBytesNeeded;
62 DWORD dwCount;
63
64 /* Set the first items in each tree view */
66 NULL,
68 if (hSCManager)
69 {
70 hService = OpenServiceW(hSCManager,
71 lpServiceName,
73 if (hService)
74 {
75 /* Does this have any dependencies? */
76 if (!EnumDependentServicesW(hService,
78 NULL,
79 0,
80 &dwBytesNeeded,
81 &dwCount) &&
83 {
85 0,
86 dwBytesNeeded);
87 if (lpDependencies)
88 {
89 /* Get the list of dependents */
90 if (EnumDependentServicesW(hService,
92 lpDependencies,
93 dwBytesNeeded,
94 &dwBytesNeeded,
95 &dwCount))
96 {
97 /* Set the count */
98 *lpdwCount = dwCount;
99 }
100 else
101 {
103 0,
104 lpDependencies);
105
106 lpDependencies = NULL;
107 }
108 }
109 }
110
111 CloseServiceHandle(hService);
112 }
113
115 }
116
117 return lpDependencies;
118}
119
120VOID
122 HTREEITEM hParent,
123 LPWSTR lpServiceName)
124{
125
126 LPENUM_SERVICE_STATUSW lpServiceStatus;
127 LPWSTR lpNoDepends;
128 DWORD count, i;
129 BOOL bHasChildren;
130
131 /* Get a list of service dependents */
132 lpServiceStatus = TV2_GetDependants(lpServiceName, &count);
133 if (lpServiceStatus)
134 {
135 for (i = 0; i < count; i++)
136 {
137 /* Does this item need a +/- box? */
138 bHasChildren = TV2_HasDependantServices(lpServiceStatus[i].lpServiceName);
139
140 /* Add it */
142 hParent,
143 lpServiceStatus[i].lpDisplayName,
144 lpServiceStatus[i].lpServiceName,
145 lpServiceStatus[i].ServiceStatus.dwServiceType,
146 bHasChildren);
147 }
148
150 0,
151 lpServiceStatus);
152 }
153 else
154 {
155 /* If there is no parent, set the tree to 'no dependencies' */
156 if (!hParent)
157 {
158 /* Load the 'No dependencies' string */
160
162 NULL,
163 lpNoDepends,
164 NULL,
165 0,
166 FALSE);
167
168 LocalFree(lpNoDepends);
169
170 /* Disable the window */
171 EnableWindow(pDependData->hDependsTreeView2, FALSE);
172 }
173 }
174}
175
176BOOL
178 LPWSTR lpServiceName)
179{
180 BOOL bRet = FALSE;
181
182 /* Associate the imagelist with TV2 */
183 pDependData->hDependsTreeView2 = GetDlgItem(pDependData->hDependsWnd, IDC_DEPEND_TREE2);
184 if (!pDependData->hDependsTreeView2)
185 {
187 pDependData->hDependsImageList = NULL;
188 return FALSE;
189 }
191 pDependData->hDependsImageList,
193
194 /* Set the first items in the control */
195 TV2_AddDependantsToTree(pDependData, NULL, lpServiceName);
196
197 return bRet;
198}
INT AllocAndLoadString(OUT LPTSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:59
HTREEITEM AddItemToTreeView(HWND hTreeView, HTREEITEM hRoot, LPWSTR lpDisplayName, LPWSTR lpServiceName, ULONG serviceType, BOOL bHasChildren)
HANDLE ProcessHeap
Definition: servman.c:15
#define IDC_DEPEND_TREE2
Definition: resource.h:176
#define IDS_NO_DEPENDS
Definition: resource.h:178
HINSTANCE hInstance
Definition: charmap.c:19
#define ERROR_MORE_DATA
Definition: dderror.h:13
BOOL TV2_HasDependantServices(LPWSTR lpServiceName)
VOID TV2_AddDependantsToTree(PDEPENDDATA pDependData, HTREEITEM hParent, LPWSTR lpServiceName)
BOOL TV2_Initialize(PDEPENDDATA pDependData, LPWSTR lpServiceName)
LPENUM_SERVICE_STATUS TV2_GetDependants(LPWSTR lpServiceName, LPDWORD lpdwCount)
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI ImageList_Destroy(HIMAGELIST himl)
Definition: imagelist.c:928
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define TVSIL_NORMAL
Definition: commctrl.h:3443
#define TreeView_SetImageList(hwnd, himl, iImage)
Definition: commctrl.h:3447
SC_HANDLE hSCManager
Definition: sc.c:12
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2068
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2160
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
BOOL WINAPI EnumDependentServicesW(SC_HANDLE hService, DWORD dwServiceState, LPENUM_SERVICE_STATUSW lpServices, DWORD cbBufSize, LPDWORD pcbBytesNeeded, LPDWORD lpServicesReturned)
Definition: scm.c:1033
HIMAGELIST hDependsImageList
Definition: precomp.h:139
HWND hDependsTreeView2
Definition: precomp.h:142
HWND hDependsWnd
Definition: precomp.h:140
SERVICE_STATUS ServiceStatus
Definition: winsvc.h:132
LPWSTR lpDisplayName
Definition: winsvc.h:131
LPWSTR lpServiceName
Definition: winsvc.h:130
DWORD dwServiceType
Definition: winsvc.h:99
uint32_t * LPDWORD
Definition: typedefs.h:59
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define SERVICE_STATE_ALL
Definition: winsvc.h:52
#define SERVICE_QUERY_STATUS
Definition: winsvc.h:55
#define EnumDependentServices
Definition: winsvc.h:570
struct _ENUM_SERVICE_STATUSW * LPENUM_SERVICE_STATUSW
#define SERVICE_ENUMERATE_DEPENDENTS
Definition: winsvc.h:56
#define SC_MANAGER_ALL_ACCESS
Definition: winsvc.h:13
#define SERVICE_QUERY_CONFIG
Definition: winsvc.h:53
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
WCHAR * LPWSTR
Definition: xmlstorage.h:184