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
|
2015-09-09 13:13:35 +00:00
|
|
|
* FILE: base/applications/sc/delete.c
|
2006-08-31 17:59:02 +00:00
|
|
|
* PURPOSE: Delete a service
|
|
|
|
* COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
|
2006-02-16 23:18:11 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sc.h"
|
|
|
|
|
|
|
|
BOOL Delete(LPCTSTR ServiceName)
|
|
|
|
{
|
2006-08-31 17:59:02 +00:00
|
|
|
SC_HANDLE hSCManager = NULL;
|
|
|
|
SC_HANDLE hSc = NULL;
|
2016-06-15 21:28:33 +00:00
|
|
|
BOOL bRet = TRUE;
|
2006-02-16 23:18:11 +00:00
|
|
|
|
2006-08-31 17:59:02 +00:00
|
|
|
#ifdef SCDBG
|
|
|
|
_tprintf(_T("service to delete - %s\n\n"), ServiceName);
|
2006-02-16 23:18:11 +00:00
|
|
|
#endif
|
|
|
|
|
2006-08-31 17:59:02 +00:00
|
|
|
hSCManager = OpenSCManager(NULL,
|
|
|
|
NULL,
|
|
|
|
SC_MANAGER_CONNECT);
|
2016-06-15 21:28:33 +00:00
|
|
|
if (hSCManager == NULL)
|
2006-02-16 23:18:11 +00:00
|
|
|
{
|
2016-06-15 21:28:33 +00:00
|
|
|
_tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
|
|
|
|
bRet = FALSE;
|
|
|
|
goto done;
|
2006-02-16 23:18:11 +00:00
|
|
|
}
|
|
|
|
|
2016-06-15 21:28:33 +00:00
|
|
|
hSc = OpenService(hSCManager, ServiceName, DELETE);
|
|
|
|
if (hSc == NULL)
|
|
|
|
{
|
|
|
|
_tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
|
|
|
|
bRet = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!DeleteService(hSc))
|
|
|
|
{
|
|
|
|
_tprintf(_T("[SC] DeleteService FAILED %lu:\n\n"), GetLastError());
|
|
|
|
bRet = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
_tprintf(_T("[SC] DeleteService SUCCESS\n\n"));
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (bRet == FALSE)
|
|
|
|
ReportLastError();
|
|
|
|
|
|
|
|
if (hSc)
|
|
|
|
CloseServiceHandle(hSc);
|
2006-08-31 17:59:02 +00:00
|
|
|
|
2016-06-15 21:28:33 +00:00
|
|
|
if (hSCManager)
|
|
|
|
CloseServiceHandle(hSCManager);
|
2006-08-31 17:59:02 +00:00
|
|
|
|
2016-06-15 21:28:33 +00:00
|
|
|
return bRet;
|
2006-02-16 23:18:11 +00:00
|
|
|
}
|