2006-02-16 23:18:11 +00:00
|
|
|
/*
|
2006-08-31 17:59:02 +00:00
|
|
|
* PROJECT: ReactOS Services
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: base/system/sc/start.c
|
|
|
|
* PURPOSE: Start a service
|
|
|
|
* COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
|
2006-02-16 23:18:11 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sc.h"
|
|
|
|
|
|
|
|
BOOL Start(LPCTSTR ServiceName, LPCTSTR *ServiceArgs, INT ArgCount)
|
|
|
|
{
|
2009-02-05 12:56:11 +00:00
|
|
|
SC_HANDLE hSCManager = NULL;
|
|
|
|
SC_HANDLE hSc = NULL;
|
2006-08-31 17:59:02 +00:00
|
|
|
LPSERVICE_STATUS_PROCESS pServiceInfo = NULL;
|
|
|
|
|
|
|
|
#ifdef SCDBG
|
|
|
|
LPCTSTR *TmpArgs = ServiceArgs;
|
|
|
|
INT TmpCnt = ArgCount;
|
|
|
|
_tprintf(_T("service to control - %s\n"), ServiceName);
|
|
|
|
_tprintf(_T("Arguments:\n"));
|
|
|
|
while (TmpCnt)
|
2006-02-16 23:18:11 +00:00
|
|
|
{
|
2006-08-31 17:59:02 +00:00
|
|
|
_tprintf(_T(" %s\n"), *TmpArgs);
|
|
|
|
TmpArgs++;
|
|
|
|
TmpCnt--;
|
2006-02-16 23:18:11 +00:00
|
|
|
}
|
2006-08-31 17:59:02 +00:00
|
|
|
_tprintf(_T("\n"));
|
|
|
|
#endif /* SCDBG */
|
|
|
|
|
|
|
|
hSCManager = OpenSCManager(NULL,
|
|
|
|
NULL,
|
|
|
|
SC_MANAGER_CONNECT);
|
|
|
|
if (hSCManager == NULL)
|
2006-09-01 16:55:36 +00:00
|
|
|
{
|
|
|
|
ReportLastError();
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-02-16 23:18:11 +00:00
|
|
|
|
2006-08-31 17:59:02 +00:00
|
|
|
hSc = OpenService(hSCManager,
|
|
|
|
ServiceName,
|
|
|
|
SERVICE_START | SERVICE_QUERY_STATUS);
|
2006-02-16 23:18:11 +00:00
|
|
|
|
|
|
|
if (hSc == NULL)
|
2006-08-31 17:59:02 +00:00
|
|
|
goto fail;
|
2006-02-16 23:18:11 +00:00
|
|
|
|
2009-02-05 13:30:24 +00:00
|
|
|
if (!ArgCount)
|
|
|
|
{
|
|
|
|
ServiceArgs = NULL;
|
|
|
|
}
|
|
|
|
|
2006-08-31 17:59:02 +00:00
|
|
|
if (! StartService(hSc,
|
|
|
|
ArgCount,
|
|
|
|
ServiceArgs))
|
2006-02-16 23:18:11 +00:00
|
|
|
{
|
2006-10-07 14:35:22 +00:00
|
|
|
_tprintf(_T("[SC] StartService FAILED %lu:\n\n"), GetLastError());
|
2006-08-31 17:59:02 +00:00
|
|
|
goto fail;
|
2006-02-16 23:18:11 +00:00
|
|
|
}
|
|
|
|
|
2006-09-01 16:55:36 +00:00
|
|
|
pServiceInfo = QueryService(ServiceName);
|
|
|
|
if (pServiceInfo != NULL)
|
2006-02-16 23:18:11 +00:00
|
|
|
{
|
2006-09-01 16:55:36 +00:00
|
|
|
PrintService(ServiceName,
|
|
|
|
pServiceInfo,
|
|
|
|
TRUE);
|
2006-02-16 23:18:11 +00:00
|
|
|
}
|
|
|
|
|
2006-08-31 17:59:02 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, pServiceInfo);
|
2006-02-16 23:18:11 +00:00
|
|
|
CloseServiceHandle(hSc);
|
2006-08-31 17:59:02 +00:00
|
|
|
CloseServiceHandle(hSCManager);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
ReportLastError();
|
|
|
|
if (hSc) CloseServiceHandle(hSc);
|
|
|
|
if (hSCManager) CloseServiceHandle(hSCManager);
|
|
|
|
return FALSE;
|
|
|
|
|
2006-02-16 23:18:11 +00:00
|
|
|
}
|