mirror of
https://github.com/reactos/reactos.git
synced 2025-04-27 00:50:23 +00:00
[SC]
- Reorganized some commands in order to add erros and success messages. - Added error and success messages. - Enabled usage text for the failure command. svn path=/trunk/; revision=71645
This commit is contained in:
parent
3320cc95a2
commit
ffe9e79d41
7 changed files with 153 additions and 104 deletions
|
@ -16,9 +16,11 @@ Control(DWORD Control,
|
|||
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 @@ Control(DWORD Control,
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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,38 +71,45 @@ BOOL Create(LPCTSTR *ServiceArgs, INT ArgCount)
|
|||
#endif
|
||||
|
||||
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
|
||||
|
||||
if (hSCManager != NULL)
|
||||
if (hSCManager == 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);
|
||||
|
||||
if (hSc != NULL)
|
||||
{
|
||||
_tprintf(_T("[SC] CreateService SUCCESS\n"));
|
||||
|
||||
CloseServiceHandle(hSc);
|
||||
bRet = TRUE;
|
||||
}
|
||||
else
|
||||
ReportLastError();
|
||||
|
||||
CloseServiceHandle(hSCManager);
|
||||
_tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
|
||||
bRet = FALSE;
|
||||
goto done;
|
||||
}
|
||||
else
|
||||
|
||||
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)
|
||||
{
|
||||
_tprintf(_T("[SC] CreateService FAILED %lu:\n\n"), GetLastError());
|
||||
bRet = FALSE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
_tprintf(_T("[SC] CreateService SUCCESS\n\n"));
|
||||
|
||||
done:
|
||||
if (bRet == FALSE)
|
||||
ReportLastError();
|
||||
|
||||
if (hService)
|
||||
CloseServiceHandle(hService);
|
||||
|
||||
if (hSCManager)
|
||||
CloseServiceHandle(hSCManager);
|
||||
|
||||
if (lpBuffer != NULL)
|
||||
HeapFree(GetProcessHeap(), 0, lpBuffer);
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ BOOL Delete(LPCTSTR ServiceName)
|
|||
{
|
||||
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 @@ BOOL Delete(LPCTSTR ServiceName)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ BOOL SdSet(LPCTSTR ServiceName, LPCTSTR StringSecurityDescriptor)
|
|||
SC_MANAGER_CONNECT);
|
||||
if (hManager == NULL)
|
||||
{
|
||||
_tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
|
||||
bResult = FALSE;
|
||||
goto done;
|
||||
}
|
||||
|
@ -33,6 +34,7 @@ BOOL SdSet(LPCTSTR ServiceName, LPCTSTR StringSecurityDescriptor)
|
|||
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 @@ BOOL SdSet(LPCTSTR ServiceName, LPCTSTR StringSecurityDescriptor)
|
|||
&pSecurityDescriptor,
|
||||
&ulSecurityDescriptorSize))
|
||||
{
|
||||
_tprintf(_T("[SC] ConvertStringSecurityDescriptorToSecurityDescriptor FAILED %lu:\n\n"), GetLastError());
|
||||
bResult = FALSE;
|
||||
goto done;
|
||||
}
|
||||
|
@ -50,6 +53,7 @@ BOOL SdSet(LPCTSTR ServiceName, LPCTSTR StringSecurityDescriptor)
|
|||
DACL_SECURITY_INFORMATION,
|
||||
pSecurityDescriptor))
|
||||
{
|
||||
_tprintf(_T("[SC] SetServiceObjectSecurity FAILED %lu:\n\n"), GetLastError());
|
||||
bResult = FALSE;
|
||||
goto done;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ BOOL SdShow(LPCTSTR ServiceName)
|
|||
SC_MANAGER_CONNECT);
|
||||
if (hManager == NULL)
|
||||
{
|
||||
_tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
|
||||
bResult = FALSE;
|
||||
goto done;
|
||||
}
|
||||
|
@ -34,6 +35,7 @@ BOOL SdShow(LPCTSTR ServiceName)
|
|||
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 @@ BOOL SdShow(LPCTSTR ServiceName)
|
|||
{
|
||||
if (cbBytesNeeded == 0)
|
||||
{
|
||||
_tprintf(_T("[SC] QueryServiceObjectSecurity FAILED %lu:\n\n"), GetLastError());
|
||||
bResult = FALSE;
|
||||
goto done;
|
||||
}
|
||||
|
@ -55,6 +58,7 @@ BOOL SdShow(LPCTSTR ServiceName)
|
|||
if (pSecurityDescriptor == NULL)
|
||||
{
|
||||
SetLastError(ERROR_OUTOFMEMORY);
|
||||
_tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
|
||||
bResult = FALSE;
|
||||
goto done;
|
||||
}
|
||||
|
@ -65,6 +69,7 @@ BOOL SdShow(LPCTSTR ServiceName)
|
|||
cbBytesNeeded,
|
||||
&cbBytesNeeded))
|
||||
{
|
||||
_tprintf(_T("[SC] QueryServiceObjectSecurity FAILED %lu:\n\n"), GetLastError());
|
||||
bResult = FALSE;
|
||||
goto done;
|
||||
}
|
||||
|
@ -75,6 +80,7 @@ BOOL SdShow(LPCTSTR ServiceName)
|
|||
&pStringBuffer,
|
||||
NULL))
|
||||
{
|
||||
_tprintf(_T("[SC] ConvertSecurityDescriptorToStringSecurityDescriptor FAILED %lu:\n\n"), GetLastError());
|
||||
bResult = FALSE;
|
||||
goto done;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ BOOL Start(LPCTSTR ServiceName, LPCTSTR *ServiceArgs, INT ArgCount)
|
|||
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 @@ BOOL Start(LPCTSTR ServiceName, LPCTSTR *ServiceArgs, INT ArgCount)
|
|||
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 @@ BOOL Start(LPCTSTR ServiceName, LPCTSTR *ServiceArgs, INT ArgCount)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ VOID MainUsage(VOID)
|
|||
_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 CreateUsage(VOID)
|
|||
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)
|
||||
|
|
Loading…
Reference in a new issue