ReactOS  0.4.12-dev-18-gf469aca
depend.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/sc/depend.c
5  * PURPOSE:
6  * COPYRIGHT: Copyright 2016 Eric Kohl
7  *
8  */
9 
10 #include "sc.h"
11 
13 {
14  SC_HANDLE hManager = NULL;
15  SC_HANDLE hService = NULL;
16  BOOL bResult = TRUE;
17  DWORD BufferSize = 0;
18  DWORD EntriesRead = 0;
20  DWORD i;
21 
22  hManager = OpenSCManager(NULL,
23  NULL,
25  if (hManager == NULL)
26  {
27  _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
28  bResult = FALSE;
29  goto done;
30  }
31 
32  hService = OpenService(hManager, ServiceName, SERVICE_ENUMERATE_DEPENDENTS);
33  if (hService == NULL)
34  {
35  _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
36  bResult = FALSE;
37  goto done;
38  }
39 
40  if (!EnumDependentServices(hService,
42  NULL,
43  0,
44  &BufferSize,
45  &EntriesRead))
46  {
47  if (BufferSize == 0)
48  {
49  _tprintf(_T("[SC] EnumDependentServices FAILED %lu:\n\n"), GetLastError());
50  bResult = FALSE;
51  goto done;
52  }
53  }
54 
55  pBuffer = HeapAlloc(GetProcessHeap(), 0, BufferSize);
56  if (pBuffer == NULL)
57  {
59  _tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
60  bResult = FALSE;
61  goto done;
62  }
63 
64  if (!EnumDependentServices(hService,
66  pBuffer,
67  BufferSize,
68  &BufferSize,
69  &EntriesRead))
70  {
71  _tprintf(_T("[SC] EnumDependentServices FAILED %lu:\n\n"), GetLastError());
72  bResult = FALSE;
73  goto done;
74  }
75 
76  _tprintf(_T("Enum: entriesRead = %lu\n"), EntriesRead);
77 
78  for (i = 0; i < EntriesRead; i++)
79  {
80  _tprintf(_T("\n"));
81  _tprintf(_T("SERVICE_NAME: %s\n"), pBuffer[i].lpServiceName);
82  _tprintf(_T("DISPLAY_NAME: %s\n"), pBuffer[i].lpDisplayName);
83  PrintServiceStatus(&pBuffer[i].ServiceStatus);
84  }
85 
86 done:
87  if (bResult == FALSE)
89 
90  if (pBuffer != NULL)
91  HeapFree(GetProcessHeap(), 0, pBuffer);
92 
93  if (hService)
94  CloseServiceHandle(hService);
95 
96  if (hManager)
97  CloseServiceHandle(hManager);
98 
99  return bResult;
100 }
#define _tprintf
Definition: tchar.h:506
#define TRUE
Definition: types.h:120
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define EnumDependentServices
Definition: winsvc.h:570
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define SERVICE_STATE_ALL
Definition: winsvc.h:52
#define SERVICE_ENUMERATE_DEPENDENTS
Definition: winsvc.h:56
#define OpenService
Definition: winsvc.h:576
GLenum GLclampf GLint i
Definition: glfuncs.h:14
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:576
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
VOID PrintServiceStatus(LPSERVICE_STATUS pStatus)
Definition: print.c:39
#define OpenSCManager
Definition: winsvc.h:575
#define _T(x)
Definition: vfdio.h:22
unsigned int BOOL
Definition: ntddk_ex.h:94
LPTSTR ServiceName
Definition: ServiceMain.c:15
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define BufferSize
Definition: classpnp.h:419
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
VOID ReportLastError(VOID)
Definition: sc.c:15
BOOL EnumDepend(LPCTSTR ServiceName)
Definition: depend.c:12
SERVICE_STATUS ServiceStatus
Definition: dhcpcsvc.c:18
_In_ LPCSTR _Out_writes_to_opt_ cchDisplayName LPSTR lpDisplayName
Definition: winbase.h:2730
#define HeapFree(x, y, z)
Definition: compat.h:394
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13