Add some error and success messages to the config and description commands.

svn path=/trunk/; revision=71640
This commit is contained in:
Eric Kohl 2016-06-14 22:00:34 +00:00
parent 464f46d352
commit caa61ecac3
2 changed files with 20 additions and 1 deletions

View file

@ -2,7 +2,7 @@
* PROJECT: ReactOS Services * PROJECT: ReactOS Services
* LICENSE: GPL - See COPYING in the top level directory * LICENSE: GPL - See COPYING in the top level directory
* FILE: base/applications/sc/config.c * FILE: base/applications/sc/config.c
* PURPOSE: Set the service configuration * PURPOSE: Query/Set the service configuration
* COPYRIGHT: Copyright 2016 Eric Kohl * COPYRIGHT: Copyright 2016 Eric Kohl
* *
*/ */
@ -28,6 +28,7 @@ BOOL QueryConfig(LPCTSTR ServiceName)
SC_MANAGER_CONNECT); SC_MANAGER_CONNECT);
if (hManager == NULL) if (hManager == NULL)
{ {
_tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
bResult = FALSE; bResult = FALSE;
goto done; goto done;
} }
@ -35,6 +36,7 @@ BOOL QueryConfig(LPCTSTR ServiceName)
hService = OpenService(hManager, ServiceName, SERVICE_QUERY_CONFIG); hService = OpenService(hManager, ServiceName, SERVICE_QUERY_CONFIG);
if (hService == NULL) if (hService == NULL)
{ {
_tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
bResult = FALSE; bResult = FALSE;
goto done; goto done;
} }
@ -46,6 +48,7 @@ BOOL QueryConfig(LPCTSTR ServiceName)
{ {
if (cbBytesNeeded == 0) if (cbBytesNeeded == 0)
{ {
_tprintf(_T("[SC] QueryServiceConfig FAILED %lu:\n\n"), GetLastError());
bResult = FALSE; bResult = FALSE;
goto done; goto done;
} }
@ -55,6 +58,7 @@ BOOL QueryConfig(LPCTSTR ServiceName)
if (pServiceConfig == NULL) if (pServiceConfig == NULL)
{ {
SetLastError(ERROR_OUTOFMEMORY); SetLastError(ERROR_OUTOFMEMORY);
_tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
bResult = FALSE; bResult = FALSE;
goto done; goto done;
} }
@ -64,10 +68,13 @@ BOOL QueryConfig(LPCTSTR ServiceName)
cbBytesNeeded, cbBytesNeeded,
&cbBytesNeeded)) &cbBytesNeeded))
{ {
_tprintf(_T("[SC] QueryServiceConfig FAILED %lu:\n\n"), GetLastError());
bResult = FALSE; bResult = FALSE;
goto done; goto done;
} }
_tprintf(_T("[SC] QueryServiceConfig SUCCESS\n\n"));
_tprintf(_T("SERVICE_NAME: %s\n"), ServiceName); _tprintf(_T("SERVICE_NAME: %s\n"), ServiceName);
_tprintf(_T(" TYPE : %-3lx "), pServiceConfig->dwServiceType); _tprintf(_T(" TYPE : %-3lx "), pServiceConfig->dwServiceType);
switch (pServiceConfig->dwServiceType) switch (pServiceConfig->dwServiceType)

View file

@ -26,6 +26,7 @@ BOOL QueryDescription(LPCTSTR ServiceName)
SC_MANAGER_CONNECT); SC_MANAGER_CONNECT);
if (hManager == NULL) if (hManager == NULL)
{ {
_tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
bResult = FALSE; bResult = FALSE;
goto done; goto done;
} }
@ -33,6 +34,7 @@ BOOL QueryDescription(LPCTSTR ServiceName)
hService = OpenService(hManager, ServiceName, SERVICE_QUERY_CONFIG); hService = OpenService(hManager, ServiceName, SERVICE_QUERY_CONFIG);
if (hService == NULL) if (hService == NULL)
{ {
_tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
bResult = FALSE; bResult = FALSE;
goto done; goto done;
} }
@ -45,6 +47,7 @@ BOOL QueryDescription(LPCTSTR ServiceName)
{ {
if (cbBytesNeeded == 0) if (cbBytesNeeded == 0)
{ {
_tprintf(_T("[SC] QueryServiceConfig2 FAILED %lu:\n\n"), GetLastError());
bResult = FALSE; bResult = FALSE;
goto done; goto done;
} }
@ -54,6 +57,7 @@ BOOL QueryDescription(LPCTSTR ServiceName)
if (pServiceDescription == NULL) if (pServiceDescription == NULL)
{ {
SetLastError(ERROR_OUTOFMEMORY); SetLastError(ERROR_OUTOFMEMORY);
_tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
bResult = FALSE; bResult = FALSE;
goto done; goto done;
} }
@ -64,10 +68,13 @@ BOOL QueryDescription(LPCTSTR ServiceName)
cbBytesNeeded, cbBytesNeeded,
&cbBytesNeeded)) &cbBytesNeeded))
{ {
_tprintf(_T("[SC] QueryServiceConfig2 FAILED %lu:\n\n"), GetLastError());
bResult = FALSE; bResult = FALSE;
goto done; goto done;
} }
_tprintf(_T("[SC] QueryServiceConfig2 SUCCESS\n\n"));
_tprintf(_T("SERVICE_NAME: %s\n"), ServiceName); _tprintf(_T("SERVICE_NAME: %s\n"), ServiceName);
_tprintf(_T(" DESCRIPTION : %s\n"), _tprintf(_T(" DESCRIPTION : %s\n"),
(pServiceDescription->lpDescription) ? pServiceDescription->lpDescription : _T("")); (pServiceDescription->lpDescription) ? pServiceDescription->lpDescription : _T(""));
@ -105,6 +112,7 @@ BOOL SetDescription(LPCTSTR ServiceName, LPCTSTR Description)
SC_MANAGER_CONNECT); SC_MANAGER_CONNECT);
if (hManager == NULL) if (hManager == NULL)
{ {
_tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
bResult = FALSE; bResult = FALSE;
goto done; goto done;
} }
@ -112,6 +120,7 @@ BOOL SetDescription(LPCTSTR ServiceName, LPCTSTR Description)
hService = OpenService(hManager, ServiceName, SERVICE_CHANGE_CONFIG); hService = OpenService(hManager, ServiceName, SERVICE_CHANGE_CONFIG);
if (hService == NULL) if (hService == NULL)
{ {
_tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
bResult = FALSE; bResult = FALSE;
goto done; goto done;
} }
@ -122,10 +131,13 @@ BOOL SetDescription(LPCTSTR ServiceName, LPCTSTR Description)
SERVICE_CONFIG_DESCRIPTION, SERVICE_CONFIG_DESCRIPTION,
(LPBYTE)&ServiceDescription)) (LPBYTE)&ServiceDescription))
{ {
_tprintf(_T("[SC] ChangeServiceConfig2 FAILED %lu:\n\n"), GetLastError());
bResult = FALSE; bResult = FALSE;
goto done; goto done;
} }
_tprintf(_T("[SC] ChangeServiceConfig2 SUCCESS\n\n"));
done: done:
if (bResult == FALSE) if (bResult == FALSE)
ReportLastError(); ReportLastError();