ReactOS 0.4.15-dev-5672-gf73ac17
description.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/description.c
5 * PURPOSE: Query/Set the service description
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 cbBytesNeeded = 0;
18 LPSERVICE_DESCRIPTION pServiceDescription = NULL;
19
20#ifdef SCDBG
21 _tprintf(_T("service to show description - %s\n\n"), ServiceName);
22#endif
23
24 hManager = OpenSCManager(NULL,
25 NULL,
27 if (hManager == NULL)
28 {
29 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
30 bResult = FALSE;
31 goto done;
32 }
33
34 hService = OpenService(hManager, ServiceName, SERVICE_QUERY_CONFIG);
35 if (hService == NULL)
36 {
37 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
38 bResult = FALSE;
39 goto done;
40 }
41
42 if (!QueryServiceConfig2(hService,
44 NULL,
45 0,
46 &cbBytesNeeded))
47 {
48 if (cbBytesNeeded == 0)
49 {
50 _tprintf(_T("[SC] QueryServiceConfig2 FAILED %lu:\n\n"), GetLastError());
51 bResult = FALSE;
52 goto done;
53 }
54 }
55
56 pServiceDescription = HeapAlloc(GetProcessHeap(), 0, cbBytesNeeded);
57 if (pServiceDescription == NULL)
58 {
60 _tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
61 bResult = FALSE;
62 goto done;
63 }
64
65 if (!QueryServiceConfig2(hService,
67 (LPBYTE)pServiceDescription,
68 cbBytesNeeded,
69 &cbBytesNeeded))
70 {
71 _tprintf(_T("[SC] QueryServiceConfig2 FAILED %lu:\n\n"), GetLastError());
72 bResult = FALSE;
73 goto done;
74 }
75
76 _tprintf(_T("[SC] QueryServiceConfig2 SUCCESS\n\n"));
77
78 _tprintf(_T("SERVICE_NAME: %s\n"), ServiceName);
79 _tprintf(_T(" DESCRIPTION : %s\n"),
80 (pServiceDescription->lpDescription) ? pServiceDescription->lpDescription : _T(""));
81
82done:
83 if (bResult == FALSE)
85
86 if (pServiceDescription != NULL)
87 HeapFree(GetProcessHeap(), 0, pServiceDescription);
88
89 if (hService)
90 CloseServiceHandle(hService);
91
92 if (hManager)
93 CloseServiceHandle(hManager);
94
95 return bResult;
96}
97
98
100{
101 SC_HANDLE hManager = NULL;
102 SC_HANDLE hService = NULL;
103 BOOL bResult = TRUE;
104 SERVICE_DESCRIPTION ServiceDescription;
105
106#ifdef SCDBG
107 _tprintf(_T("service to set description - %s\n\n"), ServiceName);
108#endif
109
110 hManager = OpenSCManager(NULL,
111 NULL,
113 if (hManager == NULL)
114 {
115 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
116 bResult = FALSE;
117 goto done;
118 }
119
120 hService = OpenService(hManager, ServiceName, SERVICE_CHANGE_CONFIG);
121 if (hService == NULL)
122 {
123 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
124 bResult = FALSE;
125 goto done;
126 }
127
128 ServiceDescription.lpDescription = (LPTSTR)Description;
129
130 if (!ChangeServiceConfig2(hService,
132 (LPBYTE)&ServiceDescription))
133 {
134 _tprintf(_T("[SC] ChangeServiceConfig2 FAILED %lu:\n\n"), GetLastError());
135 bResult = FALSE;
136 goto done;
137 }
138
139 _tprintf(_T("[SC] ChangeServiceConfig2 SUCCESS\n\n"));
140
141done:
142 if (bResult == FALSE)
144
145 if (hService)
146 CloseServiceHandle(hService);
147
148 if (hManager)
149 CloseServiceHandle(hManager);
150
151 return bResult;
152}
static WCHAR ServiceName[]
Definition: browser.c:19
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
BOOL SetDescription(LPCTSTR ServiceName, LPCTSTR Description)
Definition: description.c:99
BOOL QueryDescription(LPCTSTR ServiceName)
Definition: description.c:12
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const WCHAR Description[]
Definition: oid.c:1266
#define GetProcessHeap()
Definition: compat.h:736
#define SetLastError(x)
Definition: compat.h:752
#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
#define _tprintf
Definition: tchar.h:506
DWORD ReportLastError(void)
Definition: loadlib.c:67
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
unsigned char * LPBYTE
Definition: typedefs.h:53
#define _T(x)
Definition: vfdio.h:22
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define OpenSCManager
Definition: winsvc.h:575
#define SERVICE_CONFIG_DESCRIPTION
Definition: winsvc.h:65
#define ChangeServiceConfig2
Definition: winsvc.h:568
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
#define SERVICE_CHANGE_CONFIG
Definition: winsvc.h:54
#define QueryServiceConfig2
Definition: winsvc.h:581
#define SERVICE_QUERY_CONFIG
Definition: winsvc.h:53
#define OpenService
Definition: winsvc.h:576
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
CHAR * LPTSTR
Definition: xmlstorage.h:192