ReactOS 0.4.16-dev-1494-gd054f63
srvpage.c File Reference
#include "precomp.h"
#include <winsvc.h>
#include <winver.h>
Include dependency graph for srvpage.c:

Go to the source code of this file.

Functions

void GetServices (void)
 
INT_PTR CALLBACK ServicesPageWndProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 

Variables

HWND hServicesPage
 
HWND hServicesListCtrl
 
HWND hServicesDialog
 

Function Documentation

◆ GetServices()

void GetServices ( void  )

Definition at line 96 of file srvpage.c.

97{
99 WORD wCodePage;
100 WORD wLangID;
101 SC_HANDLE ScHandle;
102 SC_HANDLE hService;
103 DWORD BytesNeeded = 0;
104 DWORD ResumeHandle = 0;
105 DWORD NumServices = 0;
106 DWORD dwHandle, dwLen;
107 size_t Index;
108 UINT BufLen;
109 TCHAR szStatus[128];
110 TCHAR* lpData;
112 TCHAR szStrFileInfo[80];
115
116 LPSERVICE_FAILURE_ACTIONS pServiceFailureActions = NULL;
117 LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;
118 ENUM_SERVICE_STATUS_PROCESS *pServiceStatus = NULL;
119
121 if (ScHandle != NULL)
122 {
123 if (EnumServicesStatusEx(ScHandle, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL, (LPBYTE)pServiceStatus, 0, &BytesNeeded, &NumServices, &ResumeHandle, 0) == 0)
124 {
125 /* Call function again if required size was returned */
127 {
128 /* reserve memory for service info array */
129 pServiceStatus = HeapAlloc(GetProcessHeap(), 0, BytesNeeded);
130 if (!pServiceStatus)
131 {
132 CloseServiceHandle(ScHandle);
133 return;
134 }
135
136 /* fill array with service info */
137 if (EnumServicesStatusEx(ScHandle, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL, (LPBYTE)pServiceStatus, BytesNeeded, &BytesNeeded, &NumServices, &ResumeHandle, 0) == 0)
138 {
139 HeapFree(GetProcessHeap(), 0, pServiceStatus);
140 CloseServiceHandle(ScHandle);
141 return;
142 }
143 }
144 else /* exit on failure */
145 {
146 CloseServiceHandle(ScHandle);
147 return;
148 }
149 }
150
151 if (NumServices)
152 {
153 if (!pServiceStatus)
154 {
155 CloseServiceHandle(ScHandle);
156 return;
157 }
158
159 for (Index = 0; Index < NumServices; Index++)
160 {
161 memset(&item, 0, sizeof(LV_ITEM));
162 item.mask = LVIF_TEXT;
163 item.iImage = 0;
164 item.pszText = pServiceStatus[Index].lpDisplayName;
166 item.lParam = 0;
168
169 if (pServiceStatus[Index].ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
170 {
172 }
173
174 BytesNeeded = 0;
175 hService = OpenService(ScHandle, pServiceStatus[Index].lpServiceName, SC_MANAGER_CONNECT);
176 if (hService != NULL)
177 {
178 /* check if service is required by the system*/
179 if (!QueryServiceConfig2(hService, SERVICE_CONFIG_FAILURE_ACTIONS, (LPBYTE)NULL, 0, &BytesNeeded))
180 {
182 {
183 pServiceFailureActions = HeapAlloc(GetProcessHeap(), 0, BytesNeeded);
184 if (pServiceFailureActions == NULL)
185 {
186 HeapFree(GetProcessHeap(), 0, pServiceStatus);
187 CloseServiceHandle(hService);
188 CloseServiceHandle(ScHandle);
189 return;
190 }
191
192 if (!QueryServiceConfig2(hService, SERVICE_CONFIG_FAILURE_ACTIONS, (LPBYTE)pServiceFailureActions, BytesNeeded, &BytesNeeded))
193 {
194 HeapFree(GetProcessHeap(), 0, pServiceFailureActions);
195 HeapFree(GetProcessHeap(), 0, pServiceStatus);
196 CloseServiceHandle(hService);
197 CloseServiceHandle(ScHandle);
198 return;
199 }
200 }
201 else /* exit on failure */
202 {
203 HeapFree(GetProcessHeap(), 0, pServiceStatus);
204 CloseServiceHandle(hService);
205 CloseServiceHandle(ScHandle);
206 return;
207 }
208 }
209
210 if (pServiceFailureActions != NULL)
211 {
212 if (pServiceFailureActions->cActions && pServiceFailureActions->lpsaActions[0].Type == SC_ACTION_REBOOT)
213 {
214 LoadString(hInst, IDS_SERVICES_YES, szStatus, 128);
215 item.pszText = szStatus;
216 item.iSubItem = 1;
218 }
219 HeapFree(GetProcessHeap(), 0, pServiceFailureActions);
220 pServiceFailureActions = NULL;
221 }
222
223 /* get vendor of service binary */
224 BytesNeeded = 0;
225 if (!QueryServiceConfig(hService, NULL, 0, &BytesNeeded))
226 {
228 {
229 pServiceConfig = HeapAlloc(GetProcessHeap(), 0, BytesNeeded);
230 if (pServiceConfig == NULL)
231 {
232 HeapFree(GetProcessHeap(), 0, pServiceStatus);
233 CloseServiceHandle(hService);
234 CloseServiceHandle(ScHandle);
235 return;
236 }
237 if (!QueryServiceConfig(hService, pServiceConfig, BytesNeeded, &BytesNeeded))
238 {
239 HeapFree(GetProcessHeap(), 0, pServiceConfig);
240 HeapFree(GetProcessHeap(), 0, pServiceStatus);
241 CloseServiceHandle(hService);
242 CloseServiceHandle(ScHandle);
243 return;
244 }
245 }
246 else /* exit on failure */
247 {
248 HeapFree(GetProcessHeap(), 0, pServiceStatus);
249 CloseServiceHandle(hService);
250 CloseServiceHandle(ScHandle);
251 return;
252 }
253 }
254
255 if (pServiceConfig->lpBinaryPathName[0] != _T('"'))
256 {
257 /* Assume everything before the first space is the binary path */
258 /* FIXME: This is a reasonable heuristic but some
259 * services use unquoted paths with spaces */
262 pServiceConfig->lpBinaryPathName,
263 _tcscspn(pServiceConfig->lpBinaryPathName, _T(" ")));
264 }
265 else
266 {
267 /* Binary path is inside the quotes */
270 pServiceConfig->lpBinaryPathName + 1,
271 _tcscspn(pServiceConfig->lpBinaryPathName + 1, _T("\"")));
272 }
273
274 HeapFree(GetProcessHeap(), 0, pServiceConfig);
275 pServiceConfig = NULL;
276
277 dwLen = GetFileVersionInfoSize(FileName, &dwHandle);
278 if (dwLen)
279 {
280 lpData = HeapAlloc(GetProcessHeap(), 0, dwLen);
281 if (lpData == NULL)
282 {
283 HeapFree(GetProcessHeap(), 0, pServiceStatus);
284 CloseServiceHandle(hService);
285 CloseServiceHandle(ScHandle);
286 return;
287 }
288 if (!GetFileVersionInfo (FileName, dwHandle, dwLen, lpData))
289 {
290 HeapFree(GetProcessHeap(), 0, lpData);
291 HeapFree(GetProcessHeap(), 0, pServiceStatus);
292 CloseServiceHandle(hService);
293 CloseServiceHandle(ScHandle);
294 return;
295 }
296
297 if (VerQueryValue(lpData, _T("\\VarFileInfo\\Translation"), &pvData, (PUINT) &BufLen))
298 {
299 wCodePage = LOWORD(*(DWORD*) pvData);
300 wLangID = HIWORD(*(DWORD*) pvData);
301 wsprintf(szStrFileInfo, _T("StringFileInfo\\%04X%04X\\CompanyName"), wCodePage, wLangID);
302 }
303
304 if (VerQueryValue (lpData, szStrFileInfo, (void**) &lpBuffer, (PUINT) &BufLen))
305 {
306 item.pszText = lpBuffer;
307 item.iSubItem = 2;
309 }
310 HeapFree(GetProcessHeap(), 0, lpData);
311 }
312 else
313 {
314 LoadString(hInst, IDS_SERVICES_UNKNOWN, szStatus, 128);
315 item.pszText = szStatus;
316 item.iSubItem = 2;
318 }
319 CloseServiceHandle(hService);
320 }
321
322 LoadString(hInst, ((pServiceStatus[Index].ServiceStatusProcess.dwCurrentState == SERVICE_STOPPED) ? IDS_SERVICES_STATUS_STOPPED : IDS_SERVICES_STATUS_RUNNING), szStatus, 128);
323 item.pszText = szStatus;
324 item.iSubItem = 3;
326
327 }
328 }
329
330 HeapFree(GetProcessHeap(), 0, pServiceStatus);
331 CloseServiceHandle(ScHandle);
332 }
333
334}
#define IDS_SERVICES_YES
Definition: resource.h:111
#define IDS_SERVICES_UNKNOWN
Definition: resource.h:112
#define IDS_SERVICES_STATUS_STOPPED
Definition: resource.h:109
#define IDS_SERVICES_STATUS_RUNNING
Definition: resource.h:110
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
HINSTANCE hInst
Definition: dxdiag.c:13
#define BufLen
Definition: fatfs.h:167
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
#define _tcscspn
Definition: tchar.h:1407
unsigned int * PUINT
Definition: ndis.h:50
unsigned int UINT
Definition: ndis.h:50
#define LOWORD(l)
Definition: pedump.c:82
#define LVM_SETITEMTEXT
Definition: commctrl.h:2694
#define ListView_InsertItem(hwnd, pitem)
Definition: commctrl.h:2413
#define ListView_SetCheckState(hwndLV, i, fCheck)
Definition: commctrl.h:2679
#define ListView_GetItemCount(hwnd)
Definition: commctrl.h:2312
#define LV_ITEM
Definition: commctrl.h:2342
#define LVIF_TEXT
Definition: commctrl.h:2314
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
#define memset(x, y, z)
Definition: compat.h:39
#define _countof(array)
Definition: sndvol32.h:70
HWND hServicesListCtrl
Definition: srvpage.c:16
#define StringCchCopyN
Definition: strsafe.h:227
unsigned char * LPBYTE
Definition: typedefs.h:53
#define HIWORD(l)
Definition: typedefs.h:247
#define _T(x)
Definition: vfdio.h:22
_In_ WDFCOLLECTION _In_ ULONG Index
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ ULONG _In_opt_ PVOID pvData
Definition: winddi.h:3749
LONG_PTR LPARAM
Definition: windef.h:208
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_STATE_ALL
Definition: winsvc.h:52
#define QueryServiceConfig
Definition: winsvc.h:580
#define OpenSCManager
Definition: winsvc.h:575
@ SC_ACTION_REBOOT
Definition: winsvc.h:201
#define SC_MANAGER_ENUMERATE_SERVICE
Definition: winsvc.h:16
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define EnumServicesStatusEx
Definition: winsvc.h:572
#define SERVICE_CONFIG_FAILURE_ACTIONS
Definition: winsvc.h:66
@ SC_ENUM_PROCESS_INFO
Definition: winsvc.h:122
#define QueryServiceConfig2
Definition: winsvc.h:581
#define OpenService
Definition: winsvc.h:576
#define SendMessage
Definition: winuser.h:5954
#define wsprintf
Definition: winuser.h:5976
#define LoadString
Definition: winuser.h:5930
#define VerQueryValue
Definition: winver.h:56
#define GetFileVersionInfo
Definition: winver.h:54
#define GetFileVersionInfoSize
Definition: winver.h:53
#define SERVICE_WIN32
Definition: cmtypes.h:964
char TCHAR
Definition: xmlstorage.h:189

Referenced by ServicesPageWndProc().

◆ ServicesPageWndProc()

INT_PTR CALLBACK ServicesPageWndProc ( HWND  hDlg,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 22 of file srvpage.c.

23{
25 TCHAR szTemp[256];
26 DWORD dwStyle;
27
30
31 switch (message) {
32 case WM_INITDIALOG:
33
35 hServicesDialog = hDlg;
36
38 dwStyle = dwStyle | LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES;
40
42
43 // Initialize the application page's controls
45
47 column.pszText = szTemp;
48 column.cx = 200;
50
53 column.pszText = szTemp;
54 column.cx = 70;
56
59 column.pszText = szTemp;
60 column.cx = 200;
62
65 column.pszText = szTemp;
66 column.cx = 70;
68
70 DisableAllExcept(hDlg, IDC_SERVICES_LIST); // FIXME: Implement saving
71 return TRUE;
72
73 case WM_NOTIFY:
75 {
76 NMLISTVIEW *pnmlv = (NMLISTVIEW*)lParam;
77 UINT toggled = (pnmlv->uOldState ^ pnmlv->uNewState) & LVIS_STATEIMAGEMASK;
78 if (pnmlv->hdr.code == LVN_ITEMCHANGING && (pnmlv->uChanged & LVIF_STATE) && toggled)
79 {
80 // Only allow checkbox changes during WM_INITDIALOG
82 {
83 MessageBeep(-1);
85 return TRUE;
86 }
87 }
88 }
89 break;
90 }
91
92 return 0;
93}
#define IDC_BTN_SERVICES_ACTIVATE
Definition: resource.h:20
#define IDS_SERVICES_COLUMN_VENDOR
Definition: resource.h:83
#define IDS_SERVICES_COLUMN_SERVICE
Definition: resource.h:81
#define IDS_SERVICES_COLUMN_REQ
Definition: resource.h:82
#define IDC_SERVICES_LIST
Definition: resource.h:17
#define IDS_SERVICES_COLUMN_STATUS
Definition: resource.h:84
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
VOID DisableAllExcept(HWND hTabDlg, UINT idExcept)
Definition: msconfig.c:84
#define DWORD
Definition: nt_native.h:44
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
#define ListView_InsertColumn(hwnd, iCol, pcol)
Definition: commctrl.h:2641
#define LVIF_STATE
Definition: commctrl.h:2317
#define LVCF_WIDTH
Definition: commctrl.h:2592
#define LVN_ITEMCHANGING
Definition: commctrl.h:3135
#define LVS_EX_CHECKBOXES
Definition: commctrl.h:2736
#define LVS_EX_FULLROWSELECT
Definition: commctrl.h:2739
#define LVM_GETEXTENDEDLISTVIEWSTYLE
Definition: commctrl.h:2732
#define LVCF_TEXT
Definition: commctrl.h:2593
#define LVIS_STATEIMAGEMASK
Definition: commctrl.h:2331
#define LVM_SETEXTENDEDLISTVIEWSTYLE
Definition: commctrl.h:2729
#define LV_COLUMN
Definition: commctrl.h:2552
#define WM_NOTIFY
Definition: richedit.h:61
HWND hServicesDialog
Definition: srvpage.c:17
void GetServices(void)
Definition: srvpage.c:96
Definition: tftpd.h:60
UINT code
Definition: winuser.h:3261
UINT uNewState
Definition: commctrl.h:3041
UINT uOldState
Definition: commctrl.h:3042
#define SetWindowLongPtr
Definition: treelist.c:70
#define SWP_NOACTIVATE
Definition: winuser.h:1253
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define SWP_NOSIZE
Definition: winuser.h:1256
#define WM_INITDIALOG
Definition: winuser.h:1767
BOOL WINAPI MessageBeep(_In_ UINT uType)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
BOOL WINAPI IsWindowEnabled(_In_ HWND)
#define DWLP_MSGRESULT
Definition: winuser.h:881
#define SWP_NOOWNERZORDER
Definition: winuser.h:1260
#define SWP_NOZORDER
Definition: winuser.h:1258

Referenced by CreatePropSheet(), and OnCreate().

Variable Documentation

◆ hServicesDialog

HWND hServicesDialog

Definition at line 17 of file srvpage.c.

Referenced by ServicesPageWndProc().

◆ hServicesListCtrl

HWND hServicesListCtrl

Definition at line 16 of file srvpage.c.

Referenced by GetServices(), MsConfigWndProc(), and ServicesPageWndProc().

◆ hServicesPage

HWND hServicesPage

Definition at line 15 of file srvpage.c.

Referenced by MsConfig_OnTabWndSelChange(), MsConfigWndProc(), and OnCreate().