Create a branch for working on csrss and co.
[reactos.git] / base / applications / mscutils / servman / delete.c
1 /*
2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/delete.c
5 * PURPOSE: Delete an existing service
6 * COPYRIGHT: Copyright 2006-2007 Ged Murphy <gedmurphy@reactos.org>
7 *
8 */
9
10 #include "precomp.h"
11
12 static BOOL
13 DoDeleteService(PMAIN_WND_INFO Info,
14 HWND hDlg)
15 {
16 SC_HANDLE hSCManager;
17 SC_HANDLE hSc;
18 BOOL bRet = FALSE;
19
20 hSCManager = OpenSCManager(NULL,
21 NULL,
22 SC_MANAGER_ALL_ACCESS);
23 if (hSCManager)
24 {
25 hSc = OpenService(hSCManager,
26 Info->pCurrentService->lpServiceName,
27 DELETE);
28 if (hSc)
29 {
30 if (DeleteService(hSc))
31 {
32 LPTSTR lpSuccess;
33
34 /* report success to user */
35 if (AllocAndLoadString(&lpSuccess,
36 hInstance,
37 IDS_DELETE_SUCCESS))
38 {
39 DisplayString(lpSuccess);
40
41 HeapFree(ProcessHeap,
42 0,
43 lpSuccess);
44 }
45
46 bRet = TRUE;
47 }
48
49 CloseServiceHandle(hSc);
50 }
51
52 CloseServiceHandle(hSCManager);
53 }
54
55 return bRet;
56 }
57
58
59 INT_PTR CALLBACK
60 DeleteDialogProc(HWND hDlg,
61 UINT message,
62 WPARAM wParam,
63 LPARAM lParam)
64 {
65 PMAIN_WND_INFO Info = NULL;
66 HICON hIcon = NULL;
67
68 /* Get the window context */
69 Info = (PMAIN_WND_INFO)GetWindowLongPtr(hDlg,
70 GWLP_USERDATA);
71 if (Info == NULL && message != WM_INITDIALOG)
72 {
73 return FALSE;
74 }
75
76 switch (message)
77 {
78 case WM_INITDIALOG:
79 {
80 LPTSTR lpDescription;
81
82 Info = (PMAIN_WND_INFO)lParam;
83 if (Info != NULL)
84 {
85 SetWindowLongPtr(hDlg,
86 GWLP_USERDATA,
87 (LONG_PTR)Info);
88
89 hIcon = (HICON)LoadImage(hInstance,
90 MAKEINTRESOURCE(IDI_SM_ICON),
91 IMAGE_ICON,
92 16,
93 16,
94 0);
95 if (hIcon)
96 {
97 SendMessage(hDlg,
98 WM_SETICON,
99 ICON_SMALL,
100 (LPARAM)hIcon);
101 DestroyIcon(hIcon);
102 }
103
104 SendDlgItemMessage(hDlg,
105 IDC_DEL_NAME,
106 WM_SETTEXT,
107 0,
108 (LPARAM)Info->pCurrentService->lpDisplayName);
109
110 lpDescription = GetServiceDescription(Info->pCurrentService->lpServiceName);
111 if (lpDescription)
112 {
113 SendDlgItemMessage(hDlg,
114 IDC_DEL_DESC,
115 WM_SETTEXT,
116 0,
117 (LPARAM)lpDescription);
118 HeapFree(ProcessHeap,
119 0,
120 lpDescription);
121 }
122
123 return TRUE;
124 }
125
126 return FALSE;
127 }
128
129 case WM_COMMAND:
130 {
131 switch (LOWORD(wParam))
132 {
133 case IDOK:
134 {
135 if (DoDeleteService(Info, hDlg))
136 {
137 (void)ListView_DeleteItem(Info->hListView,
138 Info->SelectedItem);
139 UpdateServiceCount(Info);
140 }
141 EndDialog(hDlg,
142 LOWORD(wParam));
143 return TRUE;
144 }
145
146 case IDCANCEL:
147 {
148 EndDialog(hDlg,
149 LOWORD(wParam));
150 return TRUE;
151 }
152 }
153 }
154 }
155
156 return FALSE;
157 }