Sync with trunk r58740.
[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 INT_PTR CALLBACK
59 DeleteDialogProc(HWND hDlg,
60 UINT message,
61 WPARAM wParam,
62 LPARAM lParam)
63 {
64 PMAIN_WND_INFO Info = NULL;
65 HICON hIcon = NULL;
66
67 /* Get the window context */
68 Info = (PMAIN_WND_INFO)GetWindowLongPtr(hDlg,
69 GWLP_USERDATA);
70 if (Info == NULL && message != WM_INITDIALOG)
71 {
72 return FALSE;
73 }
74
75 switch (message)
76 {
77 case WM_INITDIALOG:
78 {
79 LPTSTR lpDescription;
80
81 Info = (PMAIN_WND_INFO)lParam;
82 if (Info != NULL)
83 {
84 SetWindowLongPtr(hDlg,
85 GWLP_USERDATA,
86 (LONG_PTR)Info);
87
88 hIcon = (HICON)LoadImage(hInstance,
89 MAKEINTRESOURCE(IDI_SM_ICON),
90 IMAGE_ICON,
91 16,
92 16,
93 0);
94 if (hIcon)
95 {
96 SendMessage(hDlg,
97 WM_SETICON,
98 ICON_SMALL,
99 (LPARAM)hIcon);
100 DestroyIcon(hIcon);
101 }
102
103 SendDlgItemMessage(hDlg,
104 IDC_DEL_NAME,
105 WM_SETTEXT,
106 0,
107 (LPARAM)Info->pCurrentService->lpDisplayName);
108
109 lpDescription = GetServiceDescription(Info->pCurrentService->lpServiceName);
110 if (lpDescription)
111 {
112 SendDlgItemMessage(hDlg,
113 IDC_DEL_DESC,
114 WM_SETTEXT,
115 0,
116 (LPARAM)lpDescription);
117 HeapFree(ProcessHeap,
118 0,
119 lpDescription);
120 }
121
122 return TRUE;
123 }
124
125 return FALSE;
126 }
127
128 case WM_COMMAND:
129 {
130 switch (LOWORD(wParam))
131 {
132 case IDOK:
133 {
134 if (DoDeleteService(Info, hDlg))
135 {
136 (void)ListView_DeleteItem(Info->hListView,
137 Info->SelectedItem);
138 UpdateServiceCount(Info);
139 }
140 EndDialog(hDlg,
141 LOWORD(wParam));
142 return TRUE;
143 }
144
145 case IDCANCEL:
146 {
147 EndDialog(hDlg,
148 LOWORD(wParam));
149 return TRUE;
150 }
151 }
152 }
153 }
154
155 return FALSE;
156 }