2006-04-09 12:15:43 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Applications
|
2007-01-05 20:15:07 +00:00
|
|
|
* LICENSE: LGPL - See COPYING in the top level directory
|
2015-09-09 13:13:35 +00:00
|
|
|
* FILE: base/applications/msconfig/srvpage.c
|
2006-04-09 12:15:43 +00:00
|
|
|
* PURPOSE: Services page message handler
|
|
|
|
* COPYRIGHT: Copyright 2005-2006 Christoph von Wittich <Christoph@ApiViewer.de>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include "precomp.h"
|
2006-02-16 23:18:11 +00:00
|
|
|
|
2014-01-06 21:01:43 +00:00
|
|
|
#include <winsvc.h>
|
|
|
|
#include <winver.h>
|
|
|
|
|
2006-02-16 23:18:11 +00:00
|
|
|
HWND hServicesPage;
|
|
|
|
HWND hServicesListCtrl;
|
|
|
|
HWND hServicesDialog;
|
|
|
|
|
|
|
|
void GetServices ( void );
|
|
|
|
|
|
|
|
INT_PTR CALLBACK
|
|
|
|
ServicesPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2006-08-29 13:01:47 +00:00
|
|
|
LV_COLUMN column;
|
|
|
|
TCHAR szTemp[256];
|
|
|
|
DWORD dwStyle;
|
2006-02-16 23:18:11 +00:00
|
|
|
|
2006-06-29 22:12:40 +00:00
|
|
|
UNREFERENCED_PARAMETER(lParam);
|
|
|
|
UNREFERENCED_PARAMETER(wParam);
|
2006-06-23 20:49:21 +00:00
|
|
|
|
2006-02-16 23:18:11 +00:00
|
|
|
switch (message) {
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
|
|
|
|
hServicesListCtrl = GetDlgItem(hDlg, IDC_SERVICES_LIST);
|
|
|
|
hServicesDialog = hDlg;
|
|
|
|
|
|
|
|
dwStyle = (DWORD) SendMessage(hServicesListCtrl, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
|
|
|
|
dwStyle = dwStyle | LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES;
|
|
|
|
SendMessage(hServicesListCtrl, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle);
|
|
|
|
|
2006-08-29 13:01:47 +00:00
|
|
|
SetWindowPos(hDlg, NULL, 10, 32, 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
|
2006-02-16 23:18:11 +00:00
|
|
|
|
|
|
|
// Initialize the application page's controls
|
|
|
|
column.mask = LVCF_TEXT | LVCF_WIDTH;
|
|
|
|
|
|
|
|
LoadString(hInst, IDS_SERVICES_COLUMN_SERVICE, szTemp, 256);
|
|
|
|
column.pszText = szTemp;
|
|
|
|
column.cx = 200;
|
2006-03-04 17:27:40 +00:00
|
|
|
(void)ListView_InsertColumn(hServicesListCtrl, 0, &column);
|
2006-02-16 23:18:11 +00:00
|
|
|
|
|
|
|
column.mask = LVCF_TEXT | LVCF_WIDTH;
|
|
|
|
LoadString(hInst, IDS_SERVICES_COLUMN_REQ, szTemp, 256);
|
|
|
|
column.pszText = szTemp;
|
|
|
|
column.cx = 70;
|
2006-03-04 17:27:40 +00:00
|
|
|
(void)ListView_InsertColumn(hServicesListCtrl, 1, &column);
|
2006-02-16 23:18:11 +00:00
|
|
|
|
|
|
|
column.mask = LVCF_TEXT | LVCF_WIDTH;
|
|
|
|
LoadString(hInst, IDS_SERVICES_COLUMN_VENDOR, szTemp, 256);
|
|
|
|
column.pszText = szTemp;
|
|
|
|
column.cx = 200;
|
2006-03-04 17:27:40 +00:00
|
|
|
(void)ListView_InsertColumn(hServicesListCtrl, 2, &column);
|
2006-02-16 23:18:11 +00:00
|
|
|
|
|
|
|
column.mask = LVCF_TEXT | LVCF_WIDTH;
|
|
|
|
LoadString(hInst, IDS_SERVICES_COLUMN_STATUS, szTemp, 256);
|
|
|
|
column.pszText = szTemp;
|
|
|
|
column.cx = 70;
|
2006-03-04 17:27:40 +00:00
|
|
|
(void)ListView_InsertColumn(hServicesListCtrl, 3, &column);
|
2006-02-16 23:18:11 +00:00
|
|
|
|
|
|
|
GetServices();
|
2006-08-29 13:01:47 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2006-02-16 23:18:11 +00:00
|
|
|
|
2006-08-29 13:01:47 +00:00
|
|
|
return 0;
|
2006-02-16 23:18:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetServices ( void )
|
|
|
|
{
|
|
|
|
LV_ITEM item;
|
|
|
|
WORD wCodePage;
|
|
|
|
WORD wLangID;
|
|
|
|
SC_HANDLE ScHandle;
|
|
|
|
SC_HANDLE hService;
|
|
|
|
DWORD BytesNeeded = 0;
|
|
|
|
DWORD ResumeHandle = 0;
|
2006-11-22 20:19:12 +00:00
|
|
|
DWORD NumServices = 0;
|
2006-02-16 23:18:11 +00:00
|
|
|
DWORD dwHandle, dwLen;
|
|
|
|
size_t Index;
|
|
|
|
UINT BufLen;
|
|
|
|
TCHAR szStatus[128];
|
|
|
|
TCHAR* lpData;
|
|
|
|
TCHAR* lpBuffer;
|
|
|
|
TCHAR szStrFileInfo[80];
|
|
|
|
TCHAR FileName[MAX_PATH];
|
|
|
|
LPVOID pvData;
|
|
|
|
|
|
|
|
LPSERVICE_FAILURE_ACTIONS pServiceFailureActions = NULL;
|
|
|
|
LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;
|
|
|
|
ENUM_SERVICE_STATUS_PROCESS *pServiceStatus = NULL;
|
|
|
|
|
|
|
|
ScHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);
|
2014-01-17 16:16:04 +00:00
|
|
|
if (ScHandle != NULL)
|
2006-02-16 23:18:11 +00:00
|
|
|
{
|
|
|
|
if (EnumServicesStatusEx(ScHandle, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL, (LPBYTE)pServiceStatus, 0, &BytesNeeded, &NumServices, &ResumeHandle, 0) == 0)
|
|
|
|
{
|
|
|
|
/* Call function again if required size was returned */
|
|
|
|
if (GetLastError() == ERROR_MORE_DATA)
|
|
|
|
{
|
|
|
|
/* reserve memory for service info array */
|
2014-01-17 16:16:04 +00:00
|
|
|
pServiceStatus = HeapAlloc(GetProcessHeap(), 0, BytesNeeded);
|
2006-11-22 20:19:12 +00:00
|
|
|
if (!pServiceStatus)
|
2014-04-06 21:13:18 +00:00
|
|
|
{
|
|
|
|
CloseServiceHandle(ScHandle);
|
2006-08-29 13:01:47 +00:00
|
|
|
return;
|
2014-04-06 21:13:18 +00:00
|
|
|
}
|
2006-02-16 23:18:11 +00:00
|
|
|
|
|
|
|
/* fill array with service info */
|
|
|
|
if (EnumServicesStatusEx(ScHandle, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL, (LPBYTE)pServiceStatus, BytesNeeded, &BytesNeeded, &NumServices, &ResumeHandle, 0) == 0)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, pServiceStatus);
|
2014-04-06 21:13:18 +00:00
|
|
|
CloseServiceHandle(ScHandle);
|
2006-02-16 23:18:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* exit on failure */
|
|
|
|
{
|
2014-04-06 21:13:18 +00:00
|
|
|
CloseServiceHandle(ScHandle);
|
2006-02-16 23:18:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NumServices)
|
|
|
|
{
|
|
|
|
if (!pServiceStatus)
|
2014-04-06 21:13:18 +00:00
|
|
|
{
|
|
|
|
CloseServiceHandle(ScHandle);
|
2006-02-16 23:18:11 +00:00
|
|
|
return;
|
2014-04-06 21:13:18 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 23:18:11 +00:00
|
|
|
for (Index = 0; Index < NumServices; Index++)
|
|
|
|
{
|
|
|
|
memset(&item, 0, sizeof(LV_ITEM));
|
|
|
|
item.mask = LVIF_TEXT;
|
|
|
|
item.iImage = 0;
|
|
|
|
item.pszText = pServiceStatus[Index].lpDisplayName;
|
|
|
|
item.iItem = ListView_GetItemCount(hServicesListCtrl);
|
|
|
|
item.lParam = 0;
|
|
|
|
item.iItem = ListView_InsertItem(hServicesListCtrl, &item);
|
|
|
|
|
2008-07-01 22:01:13 +00:00
|
|
|
if (pServiceStatus[Index].ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
|
|
|
|
{
|
|
|
|
ListView_SetCheckState(hServicesListCtrl, item.iItem, TRUE);
|
|
|
|
}
|
|
|
|
|
2006-02-16 23:18:11 +00:00
|
|
|
BytesNeeded = 0;
|
|
|
|
hService = OpenService(ScHandle, pServiceStatus[Index].lpServiceName, SC_MANAGER_CONNECT);
|
2014-01-17 16:16:04 +00:00
|
|
|
if (hService != NULL)
|
2006-02-16 23:18:11 +00:00
|
|
|
{
|
|
|
|
/* check if service is required by the system*/
|
2008-10-30 08:23:53 +00:00
|
|
|
if (!QueryServiceConfig2(hService, SERVICE_CONFIG_FAILURE_ACTIONS, (LPBYTE)NULL, 0, &BytesNeeded))
|
2006-02-16 23:18:11 +00:00
|
|
|
{
|
|
|
|
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
|
|
|
{
|
2014-01-17 16:16:04 +00:00
|
|
|
pServiceFailureActions = HeapAlloc(GetProcessHeap(), 0, BytesNeeded);
|
2006-11-22 20:19:12 +00:00
|
|
|
if (pServiceFailureActions == NULL)
|
2014-01-17 16:16:04 +00:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, pServiceStatus);
|
|
|
|
CloseServiceHandle(hService);
|
|
|
|
CloseServiceHandle(ScHandle);
|
2006-08-29 13:01:47 +00:00
|
|
|
return;
|
2014-01-17 16:16:04 +00:00
|
|
|
}
|
2006-02-16 23:18:11 +00:00
|
|
|
|
|
|
|
if (!QueryServiceConfig2(hService, SERVICE_CONFIG_FAILURE_ACTIONS, (LPBYTE)pServiceFailureActions, BytesNeeded, &BytesNeeded))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, pServiceFailureActions);
|
2008-10-30 08:23:53 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, pServiceStatus);
|
|
|
|
CloseServiceHandle(hService);
|
|
|
|
CloseServiceHandle(ScHandle);
|
2006-02-16 23:18:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* exit on failure */
|
|
|
|
{
|
2008-10-30 08:23:53 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, pServiceStatus);
|
|
|
|
CloseServiceHandle(hService);
|
|
|
|
CloseServiceHandle(ScHandle);
|
2006-02-16 23:18:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-29 13:01:47 +00:00
|
|
|
if (pServiceFailureActions != NULL)
|
|
|
|
{
|
2014-10-22 12:13:40 +00:00
|
|
|
if (pServiceFailureActions->cActions && pServiceFailureActions->lpsaActions[0].Type == SC_ACTION_REBOOT)
|
|
|
|
{
|
|
|
|
LoadString(hInst, IDS_SERVICES_YES, szStatus, 128);
|
|
|
|
item.pszText = szStatus;
|
|
|
|
item.iSubItem = 1;
|
|
|
|
SendMessage(hServicesListCtrl, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
|
|
|
|
}
|
2006-08-29 13:01:47 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, pServiceFailureActions);
|
|
|
|
pServiceFailureActions = NULL;
|
|
|
|
}
|
2006-02-16 23:18:11 +00:00
|
|
|
|
|
|
|
/* get vendor of service binary */
|
|
|
|
BytesNeeded = 0;
|
2008-10-30 08:23:53 +00:00
|
|
|
if (!QueryServiceConfig(hService, NULL, 0, &BytesNeeded))
|
2006-02-16 23:18:11 +00:00
|
|
|
{
|
|
|
|
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
|
|
|
{
|
2014-01-17 16:16:04 +00:00
|
|
|
pServiceConfig = HeapAlloc(GetProcessHeap(), 0, BytesNeeded);
|
2006-11-22 20:19:12 +00:00
|
|
|
if (pServiceConfig == NULL)
|
2008-10-30 08:23:53 +00:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, pServiceStatus);
|
|
|
|
CloseServiceHandle(hService);
|
|
|
|
CloseServiceHandle(ScHandle);
|
2006-08-29 13:01:47 +00:00
|
|
|
return;
|
2008-10-30 08:23:53 +00:00
|
|
|
}
|
2006-02-16 23:18:11 +00:00
|
|
|
if (!QueryServiceConfig(hService, pServiceConfig, BytesNeeded, &BytesNeeded))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, pServiceConfig);
|
2008-10-30 08:23:53 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, pServiceStatus);
|
|
|
|
CloseServiceHandle(hService);
|
|
|
|
CloseServiceHandle(ScHandle);
|
2006-02-16 23:18:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* exit on failure */
|
|
|
|
{
|
2008-10-30 08:23:53 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, pServiceStatus);
|
|
|
|
CloseServiceHandle(hService);
|
|
|
|
CloseServiceHandle(ScHandle);
|
2006-02-16 23:18:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-05 10:57:25 +00:00
|
|
|
if (pServiceConfig->lpBinaryPathName[0] != _T('"'))
|
2006-02-16 23:18:11 +00:00
|
|
|
{
|
2018-08-05 10:57:25 +00:00
|
|
|
/* Assume everything before the first space is the binary path */
|
|
|
|
/* FIXME: This is a reasonable heuristic but some
|
|
|
|
* services use unquoted paths with spaces */
|
|
|
|
StringCchCopyN(FileName,
|
|
|
|
_countof(FileName),
|
|
|
|
pServiceConfig->lpBinaryPathName,
|
|
|
|
_tcscspn(pServiceConfig->lpBinaryPathName, _T(" ")));
|
2006-02-16 23:18:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-05 10:57:25 +00:00
|
|
|
/* Binary path is inside the quotes */
|
|
|
|
StringCchCopyN(FileName,
|
|
|
|
_countof(FileName),
|
|
|
|
pServiceConfig->lpBinaryPathName + 1,
|
|
|
|
_tcscspn(pServiceConfig->lpBinaryPathName + 1, _T("\"")));
|
2006-02-16 23:18:11 +00:00
|
|
|
}
|
|
|
|
|
2006-08-29 13:01:47 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, pServiceConfig);
|
|
|
|
pServiceConfig = NULL;
|
2006-02-16 23:18:11 +00:00
|
|
|
|
2006-08-29 13:01:47 +00:00
|
|
|
dwLen = GetFileVersionInfoSize(FileName, &dwHandle);
|
2006-02-16 23:18:11 +00:00
|
|
|
if (dwLen)
|
|
|
|
{
|
2014-01-17 16:16:04 +00:00
|
|
|
lpData = HeapAlloc(GetProcessHeap(), 0, dwLen);
|
2006-11-22 20:19:12 +00:00
|
|
|
if (lpData == NULL)
|
2008-10-30 08:23:53 +00:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, pServiceStatus);
|
|
|
|
CloseServiceHandle(hService);
|
|
|
|
CloseServiceHandle(ScHandle);
|
2006-08-29 13:01:47 +00:00
|
|
|
return;
|
2008-10-30 08:23:53 +00:00
|
|
|
}
|
2006-08-29 13:01:47 +00:00
|
|
|
if (!GetFileVersionInfo (FileName, dwHandle, dwLen, lpData))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpData);
|
2008-10-30 08:23:53 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, pServiceStatus);
|
|
|
|
CloseServiceHandle(hService);
|
|
|
|
CloseServiceHandle(ScHandle);
|
2006-08-29 13:01:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-02-16 23:18:11 +00:00
|
|
|
|
|
|
|
if (VerQueryValue(lpData, _T("\\VarFileInfo\\Translation"), &pvData, (PUINT) &BufLen))
|
|
|
|
{
|
|
|
|
wCodePage = LOWORD(*(DWORD*) pvData);
|
|
|
|
wLangID = HIWORD(*(DWORD*) pvData);
|
|
|
|
wsprintf(szStrFileInfo, _T("StringFileInfo\\%04X%04X\\CompanyName"), wCodePage, wLangID);
|
|
|
|
}
|
|
|
|
|
2006-11-22 20:19:12 +00:00
|
|
|
if (VerQueryValue (lpData, szStrFileInfo, (void**) &lpBuffer, (PUINT) &BufLen))
|
2006-08-29 13:01:47 +00:00
|
|
|
{
|
2006-02-16 23:18:11 +00:00
|
|
|
item.pszText = lpBuffer;
|
|
|
|
item.iSubItem = 2;
|
|
|
|
SendMessage(hServicesListCtrl, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
|
2006-11-22 20:19:12 +00:00
|
|
|
}
|
2006-08-29 13:01:47 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpData);
|
2006-02-16 23:18:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LoadString(hInst, IDS_SERVICES_UNKNOWN, szStatus, 128);
|
|
|
|
item.pszText = szStatus;
|
|
|
|
item.iSubItem = 2;
|
|
|
|
SendMessage(hServicesListCtrl, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
|
|
|
|
}
|
|
|
|
CloseServiceHandle(hService);
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadString(hInst, ((pServiceStatus[Index].ServiceStatusProcess.dwCurrentState == SERVICE_STOPPED) ? IDS_SERVICES_STATUS_STOPPED : IDS_SERVICES_STATUS_RUNNING), szStatus, 128);
|
|
|
|
item.pszText = szStatus;
|
|
|
|
item.iSubItem = 3;
|
|
|
|
SendMessage(hServicesListCtrl, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, pServiceStatus);
|
|
|
|
CloseServiceHandle(ScHandle);
|
2006-11-22 20:19:12 +00:00
|
|
|
}
|
2006-02-16 23:18:11 +00:00
|
|
|
|
|
|
|
}
|