Author: ekohl Date: Wed Jun 15 21:28:33 2016 New Revision: 71645 URL: http://svn.reactos.org/svn/reactos?rev=71645&view=rev Log: [SC] - Reorganized some commands in order to add erros and success messages. - Added error and success messages. - Enabled usage text for the failure command.
Modified: trunk/reactos/base/applications/sc/control.c trunk/reactos/base/applications/sc/create.c trunk/reactos/base/applications/sc/delete.c trunk/reactos/base/applications/sc/sdset.c trunk/reactos/base/applications/sc/sdshow.c trunk/reactos/base/applications/sc/start.c trunk/reactos/base/applications/sc/usage.c Modified: trunk/reactos/base/applications/sc/control.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/control.c?rev=71645&r1=71644&r2=71645&view=diff ============================================================================== --- trunk/reactos/base/applications/sc/control.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/sc/control.c [iso-8859-1] Wed Jun 15 21:28:33 2016 @@ -16,9 +16,11 @@ INT ArgCount) { SC_HANDLE hSCManager = NULL; - SC_HANDLE hSc = NULL; + SC_HANDLE hService = NULL; SERVICE_STATUS Status; DWORD dwDesiredAccess = 0; + BOOL bResult = TRUE; + SERVICE_STATUS_PROCESS StatusEx; #ifdef SCDBG LPCTSTR *TmpArgs = Args; @@ -62,40 +64,50 @@ hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT); - if (hSCManager != NULL) + if (hSCManager == NULL) { - hSc = OpenService(hSCManager, - ServiceName, - dwDesiredAccess); - if (hSc != NULL) - { - if (ControlService(hSc, - Control, - &Status)) - { - SERVICE_STATUS_PROCESS StatusEx; - - /* FIXME: lazy hack ;) */ - CopyMemory(&StatusEx, &Status, sizeof(Status)); - StatusEx.dwProcessId = 0; - StatusEx.dwServiceFlags = 0; - - PrintService(ServiceName, - &StatusEx, - FALSE); - - CloseServiceHandle(hSc); - CloseServiceHandle(hSCManager); - - return TRUE; - } - } - else - _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError()); + _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError()); + bResult = FALSE; + goto done; } - ReportLastError(); - if (hSc) CloseServiceHandle(hSc); - if (hSCManager) CloseServiceHandle(hSCManager); - return FALSE; + hService = OpenService(hSCManager, + ServiceName, + dwDesiredAccess); + if (hService == NULL) + { + _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError()); + bResult = FALSE; + goto done; + } + + if (!ControlService(hService, + Control, + &Status)) + { + _tprintf(_T("[SC] ControlService FAILED %lu:\n\n"), GetLastError()); + bResult = FALSE; + goto done; + } + + /* FIXME: lazy hack ;) */ + CopyMemory(&StatusEx, &Status, sizeof(Status)); + StatusEx.dwProcessId = 0; + StatusEx.dwServiceFlags = 0; + + PrintService(ServiceName, + &StatusEx, + FALSE); + +done: + if (!bResult) + ReportLastError(); + + if (hService) + CloseServiceHandle(hService); + + if (hSCManager) + CloseServiceHandle(hSCManager); + + return bResult; } Modified: trunk/reactos/base/applications/sc/create.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/create.c?rev=71645&r1=71644&r2=71645&view=diff ============================================================================== --- trunk/reactos/base/applications/sc/create.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/sc/create.c [iso-8859-1] Wed Jun 15 21:28:33 2016 @@ -12,9 +12,9 @@ BOOL Create(LPCTSTR *ServiceArgs, INT ArgCount) { - SC_HANDLE hSCManager; - SC_HANDLE hSc; - BOOL bRet = FALSE; + SC_HANDLE hSCManager = NULL; + SC_HANDLE hService = NULL; + BOOL bRet = TRUE; INT i; INT Length; @@ -71,37 +71,44 @@ #endif hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE); + if (hSCManager == NULL) + { + _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError()); + bRet = FALSE; + goto done; + } - if (hSCManager != NULL) + hService = CreateService(hSCManager, + ServiceInfo.lpServiceName, + ServiceInfo.lpDisplayName, + SERVICE_ALL_ACCESS, + ServiceInfo.dwServiceType, + ServiceInfo.dwStartType, + ServiceInfo.dwErrorControl, + ServiceInfo.lpBinaryPathName, + ServiceInfo.lpLoadOrderGroup, + ServiceInfo.bTagId ? &ServiceInfo.dwTagId : NULL, + ServiceInfo.lpDependencies, + ServiceInfo.lpServiceStartName, + ServiceInfo.lpPassword); + if (hService == NULL) { - hSc = CreateService(hSCManager, - ServiceInfo.lpServiceName, - ServiceInfo.lpDisplayName, - SERVICE_ALL_ACCESS, - ServiceInfo.dwServiceType, - ServiceInfo.dwStartType, - ServiceInfo.dwErrorControl, - ServiceInfo.lpBinaryPathName, - ServiceInfo.lpLoadOrderGroup, - ServiceInfo.bTagId ? &ServiceInfo.dwTagId : NULL, - ServiceInfo.lpDependencies, - ServiceInfo.lpServiceStartName, - ServiceInfo.lpPassword); + _tprintf(_T("[SC] CreateService FAILED %lu:\n\n"), GetLastError()); + bRet = FALSE; + goto done; + } - if (hSc != NULL) - { - _tprintf(_T("[SC] CreateService SUCCESS\n")); + _tprintf(_T("[SC] CreateService SUCCESS\n\n")); - CloseServiceHandle(hSc); - bRet = TRUE; - } - else - ReportLastError(); +done: + if (bRet == FALSE) + ReportLastError(); + if (hService) + CloseServiceHandle(hService); + + if (hSCManager) CloseServiceHandle(hSCManager); - } - else - ReportLastError(); if (lpBuffer != NULL) HeapFree(GetProcessHeap(), 0, lpBuffer); Modified: trunk/reactos/base/applications/sc/delete.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/delete.c?rev=71645&r1=71644&r2=71645&view=diff ============================================================================== --- trunk/reactos/base/applications/sc/delete.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/sc/delete.c [iso-8859-1] Wed Jun 15 21:28:33 2016 @@ -13,6 +13,7 @@ { SC_HANDLE hSCManager = NULL; SC_HANDLE hSc = NULL; + BOOL bRet = TRUE; #ifdef SCDBG _tprintf(_T("service to delete - %s\n\n"), ServiceName); @@ -21,27 +22,39 @@ hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT); - if (hSCManager != NULL) + if (hSCManager == NULL) { - hSc = OpenService(hSCManager, ServiceName, DELETE); - if (hSc != NULL) - { - if (DeleteService(hSc)) - { - _tprintf(_T("[SC] DeleteService SUCCESS\n")); - - CloseServiceHandle(hSc); - CloseServiceHandle(hSCManager); - - return TRUE; - } - } + _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError()); + bRet = FALSE; + goto done; } - ReportLastError(); + hSc = OpenService(hSCManager, ServiceName, DELETE); + if (hSc == NULL) + { + _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError()); + bRet = FALSE; + goto done; + } - if (hSc) CloseServiceHandle(hSc); - if (hSCManager) CloseServiceHandle(hSCManager); + if (!DeleteService(hSc)) + { + _tprintf(_T("[SC] DeleteService FAILED %lu:\n\n"), GetLastError()); + bRet = FALSE; + goto done; + } - return FALSE; + _tprintf(_T("[SC] DeleteService SUCCESS\n\n")); + +done: + if (bRet == FALSE) + ReportLastError(); + + if (hSc) + CloseServiceHandle(hSc); + + if (hSCManager) + CloseServiceHandle(hSCManager); + + return bRet; } Modified: trunk/reactos/base/applications/sc/sdset.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/sdset.c?rev=71645&r1=71644&r2=71645&view=diff ============================================================================== --- trunk/reactos/base/applications/sc/sdset.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/sc/sdset.c [iso-8859-1] Wed Jun 15 21:28:33 2016 @@ -26,6 +26,7 @@ SC_MANAGER_CONNECT); if (hManager == NULL) { + _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError()); bResult = FALSE; goto done; } @@ -33,6 +34,7 @@ hService = OpenService(hManager, ServiceName, WRITE_DAC); if (hService == NULL) { + _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError()); bResult = FALSE; goto done; } @@ -42,6 +44,7 @@ &pSecurityDescriptor, &ulSecurityDescriptorSize)) { + _tprintf(_T("[SC] ConvertStringSecurityDescriptorToSecurityDescriptor FAILED %lu:\n\n"), GetLastError()); bResult = FALSE; goto done; } @@ -50,6 +53,7 @@ DACL_SECURITY_INFORMATION, pSecurityDescriptor)) { + _tprintf(_T("[SC] SetServiceObjectSecurity FAILED %lu:\n\n"), GetLastError()); bResult = FALSE; goto done; } Modified: trunk/reactos/base/applications/sc/sdshow.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/sdshow.c?rev=71645&r1=71644&r2=71645&view=diff ============================================================================== --- trunk/reactos/base/applications/sc/sdshow.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/sc/sdshow.c [iso-8859-1] Wed Jun 15 21:28:33 2016 @@ -27,6 +27,7 @@ SC_MANAGER_CONNECT); if (hManager == NULL) { + _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError()); bResult = FALSE; goto done; } @@ -34,6 +35,7 @@ hService = OpenService(hManager, ServiceName, READ_CONTROL); if (hService == NULL) { + _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError()); bResult = FALSE; goto done; } @@ -46,6 +48,7 @@ { if (cbBytesNeeded == 0) { + _tprintf(_T("[SC] QueryServiceObjectSecurity FAILED %lu:\n\n"), GetLastError()); bResult = FALSE; goto done; } @@ -55,6 +58,7 @@ if (pSecurityDescriptor == NULL) { SetLastError(ERROR_OUTOFMEMORY); + _tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError()); bResult = FALSE; goto done; } @@ -65,6 +69,7 @@ cbBytesNeeded, &cbBytesNeeded)) { + _tprintf(_T("[SC] QueryServiceObjectSecurity FAILED %lu:\n\n"), GetLastError()); bResult = FALSE; goto done; } @@ -75,6 +80,7 @@ &pStringBuffer, NULL)) { + _tprintf(_T("[SC] ConvertSecurityDescriptorToStringSecurityDescriptor FAILED %lu:\n\n"), GetLastError()); bResult = FALSE; goto done; } Modified: trunk/reactos/base/applications/sc/start.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/start.c?rev=71645&r1=71644&r2=71645&view=diff ============================================================================== --- trunk/reactos/base/applications/sc/start.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/sc/start.c [iso-8859-1] Wed Jun 15 21:28:33 2016 @@ -14,6 +14,7 @@ SC_HANDLE hSCManager = NULL; SC_HANDLE hSc = NULL; LPSERVICE_STATUS_PROCESS pServiceInfo = NULL; + BOOL bResult = TRUE; #ifdef SCDBG LPCTSTR *TmpArgs = ServiceArgs; @@ -34,28 +35,33 @@ SC_MANAGER_CONNECT); if (hSCManager == NULL) { - ReportLastError(); - return FALSE; + _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError()); + bResult = FALSE; + goto done; } hSc = OpenService(hSCManager, ServiceName, SERVICE_START | SERVICE_QUERY_STATUS); - if (hSc == NULL) - goto fail; + { + _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError()); + bResult = FALSE; + goto done; + } if (!ArgCount) { ServiceArgs = NULL; } - if (! StartService(hSc, - ArgCount, - ServiceArgs)) + if (!StartService(hSc, + ArgCount, + ServiceArgs)) { _tprintf(_T("[SC] StartService FAILED %lu:\n\n"), GetLastError()); - goto fail; + bResult = FALSE; + goto done; } pServiceInfo = QueryService(ServiceName); @@ -64,18 +70,19 @@ PrintService(ServiceName, pServiceInfo, TRUE); + + HeapFree(GetProcessHeap(), 0, pServiceInfo); } - HeapFree(GetProcessHeap(), 0, pServiceInfo); - CloseServiceHandle(hSc); - CloseServiceHandle(hSCManager); +done: + if (bResult == FALSE) + ReportLastError(); - return TRUE; + if (hSc) + CloseServiceHandle(hSc); -fail: - ReportLastError(); - if (hSc) CloseServiceHandle(hSc); - if (hSCManager) CloseServiceHandle(hSCManager); - return FALSE; + if (hSCManager) + CloseServiceHandle(hSCManager); + return bResult; } Modified: trunk/reactos/base/applications/sc/usage.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/usage.c?rev=71645&r1=71644&r2=71645&view=diff ============================================================================== --- trunk/reactos/base/applications/sc/usage.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/sc/usage.c [iso-8859-1] Wed Jun 15 21:28:33 2016 @@ -35,7 +35,7 @@ _T("\t stop : Sends a STOP request to a service.\n") _T("\t config : Changes the configuration of a service (persistant).\n") _T("\t description : Changes the description of a service.\n") -// "\t failure : Changes the actions taken by a service upon failure.\n" + _T("\t failure : Changes the actions taken by a service upon failure.\n") _T("\t qc : Queries the configuration information for a service.\n") _T("\t qdescription : Queries the description for a service.\n") _T("\t qfailure : Queries the actions taken by a service upon failure.\n") @@ -171,9 +171,9 @@ VOID ControlUsage(VOID) { _tprintf(_T("DESCRIPTION:\n") - _T(" Sends a CONTROL control request to a service.\n") - _T("USAGE:\n") - _T(" sc <server> control [service name] <value>\n")); + _T(" Sends a CONTROL control request to a service.\n") + _T("USAGE:\n") + _T(" sc <server> control [service name] <value>\n")); } VOID SdShowUsage(VOID)