[BRANCHES]
[reactos.git] / reactos / base / applications / sc / delete.c
1 /*
2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/system/sc/delete.c
5 * PURPOSE: Delete a service
6 * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
7 *
8 */
9
10 #include "sc.h"
11
12 BOOL Delete(LPCTSTR ServiceName)
13 {
14 SC_HANDLE hSCManager = NULL;
15 SC_HANDLE hSc = NULL;
16
17 #ifdef SCDBG
18 _tprintf(_T("service to delete - %s\n\n"), ServiceName);
19 #endif
20
21 hSCManager = OpenSCManager(NULL,
22 NULL,
23 SC_MANAGER_CONNECT);
24 if (hSCManager != NULL)
25 {
26 hSc = OpenService(hSCManager, ServiceName, DELETE);
27 if (hSc != NULL)
28 {
29 if (DeleteService(hSc))
30 {
31 _tprintf(_T("[SC] DeleteService SUCCESS\n"));
32
33 CloseServiceHandle(hSc);
34 CloseServiceHandle(hSCManager);
35
36 return TRUE;
37 }
38 }
39 }
40
41 ReportLastError();
42
43 if (hSc) CloseServiceHandle(hSc);
44 if (hSCManager) CloseServiceHandle(hSCManager);
45
46 return FALSE;
47 }