ReactOS  0.4.14-dev-52-g6116262
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 
12 BOOL
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 
55 TV2_GetDependants(LPWSTR lpServiceName,
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 
120 VOID
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 
176 BOOL
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  {
186  ImageList_Destroy(pDependData->hDependsImageList);
187  pDependData->hDependsImageList = NULL;
188  return FALSE;
189  }
191  pDependData->hDependsImageList,
192  TVSIL_NORMAL);
193 
194  /* Set the first items in the control */
195  TV2_AddDependantsToTree(pDependData, NULL, lpServiceName);
196 
197  return bRet;
198 }
#define TRUE
Definition: types.h:120
#define EnumDependentServices
Definition: winsvc.h:570
VOID TV2_AddDependantsToTree(PDEPENDDATA pDependData, HTREEITEM hParent, LPWSTR lpServiceName)
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
BOOL TV2_HasDependantServices(LPWSTR lpServiceName)
GLuint GLuint GLsizei count
Definition: gl.h:1545
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define SERVICE_STATE_ALL
Definition: winsvc.h:52
HIMAGELIST hDependsImageList
Definition: precomp.h:137
static INT AllocAndLoadString(OUT LPTSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:60
#define SERVICE_ENUMERATE_DEPENDENTS
Definition: winsvc.h:56
LPENUM_SERVICE_STATUS TV2_GetDependants(LPWSTR lpServiceName, LPDWORD lpdwCount)
BOOL WINAPI ImageList_Destroy(HIMAGELIST himl)
Definition: imagelist.c:928
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
HINSTANCE hInstance
Definition: charmap.c:20
unsigned int BOOL
Definition: ntddk_ex.h:94
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2103
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
smooth NULL
Definition: ftsmooth.c:416
struct _ENUM_SERVICE_STATUSW * LPENUM_SERVICE_STATUSW
#define SERVICE_QUERY_STATUS
Definition: winsvc.h:55
HWND hDependsTreeView2
Definition: precomp.h:140
#define TreeView_SetImageList(hwnd, himl, iImage)
Definition: commctrl.h:3419
BOOL WINAPI EnumDependentServicesW(SC_HANDLE hService, DWORD dwServiceState, LPENUM_SERVICE_STATUSW lpServices, DWORD cbBufSize, LPDWORD pcbBytesNeeded, LPDWORD lpServicesReturned)
Definition: scm.c:1028
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDS_NO_DEPENDS
Definition: resource.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwServiceType
Definition: winsvc.h:99
#define IDC_DEPEND_TREE2
Definition: resource.h:178
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2011
const DOCKBAR PVOID HWND hParent
Definition: tooldock.h:22
SERVICE_STATUS ServiceStatus
Definition: winsvc.h:132
SC_HANDLE hSCManager
Definition: sc.c:12
#define ERROR_MORE_DATA
Definition: dderror.h:13
HANDLE ProcessHeap
Definition: servman.c:15
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
LPWSTR lpServiceName
Definition: winsvc.h:130
LPWSTR lpDisplayName
Definition: winsvc.h:131
HWND hDependsWnd
Definition: precomp.h:138
#define SC_MANAGER_ALL_ACCESS
Definition: winsvc.h:13
#define TVSIL_NORMAL
Definition: commctrl.h:3415
uint32_t * LPDWORD
Definition: typedefs.h:57
BOOL TV2_Initialize(PDEPENDDATA pDependData, LPWSTR lpServiceName)
#define SERVICE_QUERY_CONFIG
Definition: winsvc.h:53
HTREEITEM AddItemToTreeView(HWND hTreeView, HTREEITEM hRoot, LPWSTR lpDisplayName, LPWSTR lpServiceName, ULONG serviceType, BOOL bHasChildren)
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define HeapFree(x, y, z)
Definition: compat.h:394