ReactOS  0.4.12-dev-75-g00dd17e
name.c File Reference
#include "sc.h"
Include dependency graph for name.c:

Go to the source code of this file.

Functions

BOOL GetDisplayName (LPCTSTR ServiceName)
 
BOOL GetKeyName (LPCTSTR ServiceName)
 

Function Documentation

◆ GetDisplayName()

BOOL GetDisplayName ( LPCTSTR  ServiceName)

Definition at line 12 of file name.c.

Referenced by _test_GetCurMoniker(), DECLARE_INTERFACE_(), Moniker_GetDisplayName(), ScControl(), test_editing_mode(), test_exec_editmode(), test_Hlink_Navigate(), test_HlinkGetSetMonikerReference(), test_HlinkResolveMonikerForData(), test_HlinkSite(), and test_Load().

13 {
14  SC_HANDLE hManager = NULL;
15  BOOL bResult = TRUE;
16  DWORD BufferSize = 0;
18 
19  hManager = OpenSCManager(NULL,
20  NULL,
22  if (hManager == NULL)
23  {
24  _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
25  bResult = FALSE;
26  goto done;
27  }
28 
29  if (!GetServiceDisplayName(hManager,
31  NULL,
32  &BufferSize))
33  {
34  if (BufferSize == 0)
35  {
36  _tprintf(_T("[SC] GetServiceDisplayName FAILED %lu:\n\n"), GetLastError());
37  bResult = FALSE;
38  goto done;
39  }
40  }
41 
42  pBuffer = HeapAlloc(GetProcessHeap(), 0, (BufferSize + 1) * sizeof(TCHAR));
43  if (pBuffer == NULL)
44  {
46  _tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
47  bResult = FALSE;
48  goto done;
49  }
50 
51  BufferSize++;
52  if (!GetServiceDisplayName(hManager,
54  pBuffer,
55  &BufferSize))
56  {
57  _tprintf(_T("[SC] GetServiceDisplayName FAILED %lu:\n\n"), GetLastError());
58  bResult = FALSE;
59  goto done;
60  }
61 
62  _tprintf(_T("[SC] GetServiceDisplayName SUCCESS Name = %s\n"), pBuffer);
63 
64 done:
65  if (bResult == FALSE)
67 
68  if (pBuffer != NULL)
69  HeapFree(GetProcessHeap(), 0, pBuffer);
70 
71  if (hManager)
72  CloseServiceHandle(hManager);
73 
74  return bResult;
75 }
#define _tprintf
Definition: tchar.h:506
#define TRUE
Definition: types.h:120
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
CHAR * LPTSTR
Definition: xmlstorage.h:192
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:576
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
char TCHAR
Definition: xmlstorage.h:189
#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
#define GetServiceDisplayName
Definition: winsvc.h:573
#define HeapFree(x, y, z)
Definition: compat.h:394
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

◆ GetKeyName()

BOOL GetKeyName ( LPCTSTR  ServiceName)

Definition at line 77 of file name.c.

78 {
79  SC_HANDLE hManager = NULL;
80  BOOL bResult = TRUE;
81  DWORD BufferSize = 0;
83 
84  hManager = OpenSCManager(NULL,
85  NULL,
87  if (hManager == NULL)
88  {
89  _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
90  bResult = FALSE;
91  goto done;
92  }
93 
94  if (!GetServiceKeyName(hManager,
96  NULL,
97  &BufferSize))
98  {
99  if (BufferSize == 0)
100  {
101  _tprintf(_T("[SC] GetServiceKeyName FAILED %lu:\n\n"), GetLastError());
102  bResult = FALSE;
103  goto done;
104  }
105  }
106 
107  pBuffer = HeapAlloc(GetProcessHeap(), 0, (BufferSize + 1) * sizeof(TCHAR));
108  if (pBuffer == NULL)
109  {
111  _tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
112  bResult = FALSE;
113  goto done;
114  }
115 
116  BufferSize++;
117  if (!GetServiceKeyName(hManager,
118  ServiceName,
119  pBuffer,
120  &BufferSize))
121  {
122  _tprintf(_T("[SC] GetServiceKeyName FAILED %lu:\n\n"), GetLastError());
123  bResult = FALSE;
124  goto done;
125  }
126 
127  _tprintf(_T("[SC] GetServiceKeyName SUCCESS Name = %s\n"), pBuffer);
128 
129 done:
130  if (bResult == FALSE)
131  ReportLastError();
132 
133  if (pBuffer != NULL)
134  HeapFree(GetProcessHeap(), 0, pBuffer);
135 
136  if (hManager)
137  CloseServiceHandle(hManager);
138 
139  return bResult;
140 }
#define _tprintf
Definition: tchar.h:506
#define TRUE
Definition: types.h:120
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
CHAR * LPTSTR
Definition: xmlstorage.h:192
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:576
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
char TCHAR
Definition: xmlstorage.h:189
#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
#define GetServiceKeyName
Definition: winsvc.h:574
VOID ReportLastError(VOID)
Definition: sc.c:15
#define HeapFree(x, y, z)
Definition: compat.h:394
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13