mirror of
https://github.com/reactos/reactos.git
synced 2024-12-25 16:50:57 +00:00
list services with EnumServicesStatusEx instead of reading them from registry
svn path=/trunk/; revision=19128
This commit is contained in:
parent
9178408ba6
commit
dded32cc5e
4 changed files with 104 additions and 45 deletions
|
@ -50,6 +50,7 @@ END
|
|||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
IDS_SERVICES_COLUMN_SERVICE "Dienst"
|
||||
IDS_SERVICES_COLUMN_REQ "Erforderlich"
|
||||
IDS_SERVICES_COLUMN_VENDOR "Hersteller"
|
||||
IDS_SERVICES_COLUMN_STATUS "Status"
|
||||
END
|
||||
|
@ -81,3 +82,12 @@ BEGIN
|
|||
IDS_STARTUP_COLUMN_CMD "Befehl"
|
||||
IDS_STARTUP_COLUMN_PATH "Pfad"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
IDS_SERVICES_STATUS_RUNNING "Gestartet"
|
||||
IDS_SERVICES_STATUS_STOPPED "Beendet"
|
||||
IDS_YES "Ja"
|
||||
IDS_NO "Nein"
|
||||
END
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ END
|
|||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
IDS_SERVICES_COLUMN_SERVICE "Service"
|
||||
IDS_SERVICES_COLUMN_REQ "Required"
|
||||
IDS_SERVICES_COLUMN_VENDOR "Vendor"
|
||||
IDS_SERVICES_COLUMN_STATUS "Status"
|
||||
END
|
||||
|
@ -80,3 +81,11 @@ BEGIN
|
|||
IDS_STARTUP_COLUMN_CMD "Command"
|
||||
IDS_STARTUP_COLUMN_PATH "Path"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
IDS_SERVICES_STATUS_RUNNING "Running"
|
||||
IDS_SERVICES_STATUS_STOPPED "Stopped"
|
||||
IDS_YES "Yes"
|
||||
IDS_NO "No"
|
||||
END
|
||||
|
|
|
@ -23,11 +23,12 @@
|
|||
#define IDS_TOOLS_COLUMN_NAME 2010
|
||||
#define IDS_TOOLS_COLUMN_DESCR 2011
|
||||
#define IDS_SERVICES_COLUMN_SERVICE 2012
|
||||
#define IDS_SERVICES_COLUMN_VENDOR 2013
|
||||
#define IDS_SERVICES_COLUMN_STATUS 2014
|
||||
#define IDS_STARTUP_COLUMN_ELEMENT 2015
|
||||
#define IDS_STARTUP_COLUMN_CMD 2016
|
||||
#define IDS_STARTUP_COLUMN_PATH 2017
|
||||
#define IDS_SERVICES_COLUMN_REQ 2013
|
||||
#define IDS_SERVICES_COLUMN_VENDOR 2014
|
||||
#define IDS_SERVICES_COLUMN_STATUS 2015
|
||||
#define IDS_STARTUP_COLUMN_ELEMENT 2016
|
||||
#define IDS_STARTUP_COLUMN_CMD 2017
|
||||
#define IDS_STARTUP_COLUMN_PATH 2018
|
||||
|
||||
#define IDS_TOOLS_CMD_NAME 2100
|
||||
#define IDS_TOOLS_CMD_DESCR 2101
|
||||
|
@ -49,4 +50,8 @@
|
|||
#define IDS_TOOLS_SYSDM_CMD 2114
|
||||
#define IDS_TOOLS_SYSDM_PARAM 2115
|
||||
|
||||
#define IDS_SERVICES_STATUS_STOPPED 2200
|
||||
#define IDS_SERVICES_STATUS_RUNNING 2201
|
||||
#define IDS_YES 2202
|
||||
#define IDS_NO 2203
|
||||
/* EOF */
|
||||
|
|
|
@ -33,17 +33,23 @@ ServicesPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
column.cx = 200;
|
||||
ListView_InsertColumn(hServicesListCtrl, 0, &column);
|
||||
|
||||
column.mask = LVCF_TEXT | LVCF_WIDTH;
|
||||
LoadString(hInst, IDS_SERVICES_COLUMN_REQ, szTemp, 256);
|
||||
column.pszText = szTemp;
|
||||
column.cx = 70;
|
||||
ListView_InsertColumn(hServicesListCtrl, 1, &column);
|
||||
|
||||
column.mask = LVCF_TEXT | LVCF_WIDTH;
|
||||
LoadString(hInst, IDS_SERVICES_COLUMN_VENDOR, szTemp, 256);
|
||||
column.pszText = szTemp;
|
||||
column.cx = 200;
|
||||
ListView_InsertColumn(hServicesListCtrl, 1, &column);
|
||||
ListView_InsertColumn(hServicesListCtrl, 2, &column);
|
||||
|
||||
column.mask = LVCF_TEXT | LVCF_WIDTH;
|
||||
LoadString(hInst, IDS_SERVICES_COLUMN_STATUS, szTemp, 256);
|
||||
column.pszText = szTemp;
|
||||
column.cx = 70;
|
||||
ListView_InsertColumn(hServicesListCtrl, 2, &column);
|
||||
ListView_InsertColumn(hServicesListCtrl, 3, &column);
|
||||
|
||||
GetServices();
|
||||
return TRUE;
|
||||
|
@ -55,50 +61,79 @@ ServicesPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
void
|
||||
GetServices ( void )
|
||||
{
|
||||
HKEY hKey, hSubKey;
|
||||
DWORD dwSubKeys, dwKeyLength;
|
||||
DWORD dwType, dwDataLength;
|
||||
size_t Index;
|
||||
TCHAR lpKeyName[MAX_KEY_LENGTH];
|
||||
TCHAR lpSubKey[MAX_KEY_LENGTH];
|
||||
TCHAR DisplayName[MAX_VALUE_NAME];
|
||||
TCHAR ObjectName[MAX_VALUE_NAME];
|
||||
TCHAR lpServicesKey[MAX_KEY_LENGTH] = _T("SYSTEM\\CurrentControlSet\\Services");
|
||||
LV_ITEM item;
|
||||
SC_HANDLE ScHandle;
|
||||
DWORD BufSize = 0;
|
||||
DWORD BytesNeeded = 0;
|
||||
DWORD ResumeHandle = 0;
|
||||
DWORD NumServices = 0;
|
||||
size_t Index;
|
||||
TCHAR szStatus[128];
|
||||
|
||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpServicesKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
|
||||
ENUM_SERVICE_STATUS_PROCESS *pServiceStatus = NULL;
|
||||
|
||||
ScHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);
|
||||
if (ScHandle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
if (RegQueryInfoKey(hKey, NULL, NULL, NULL, &dwSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
|
||||
if (EnumServicesStatusEx(ScHandle, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL, (LPBYTE)pServiceStatus, BufSize, &BytesNeeded, &NumServices, &ResumeHandle, 0) == 0)
|
||||
{
|
||||
for (Index = 0; Index < dwSubKeys; Index++)
|
||||
{
|
||||
dwKeyLength = MAX_KEY_LENGTH;
|
||||
if (RegEnumKeyEx(hKey, Index, lpKeyName, &dwKeyLength, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
|
||||
/* Call function again if required size was returned */
|
||||
if (GetLastError() == ERROR_MORE_DATA)
|
||||
{
|
||||
/* reserve memory for service info array */
|
||||
pServiceStatus = (ENUM_SERVICE_STATUS_PROCESS *) HeapAlloc(GetProcessHeap(), 0, BytesNeeded);
|
||||
if (pServiceStatus == NULL)
|
||||
return;
|
||||
|
||||
/* 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)
|
||||
{
|
||||
_tcscpy(lpSubKey, lpServicesKey);
|
||||
_tcscat(lpSubKey, _T("\\"));
|
||||
_tcscat(lpSubKey, lpKeyName);
|
||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, 0, KEY_READ, &hSubKey) == ERROR_SUCCESS)
|
||||
{
|
||||
dwDataLength = MAX_VALUE_NAME;
|
||||
if (RegQueryValueEx(hSubKey, _T("ObjectName"), NULL, &dwType, (LPBYTE)ObjectName, &dwDataLength) == ERROR_SUCCESS)
|
||||
{
|
||||
dwDataLength = MAX_VALUE_NAME;
|
||||
if (RegQueryValueEx(hSubKey, _T("DisplayName"), NULL, &dwType, (LPBYTE)DisplayName, &dwDataLength) == ERROR_SUCCESS)
|
||||
{
|
||||
memset(&item, 0, sizeof(LV_ITEM));
|
||||
item.mask = LVIF_TEXT;
|
||||
item.iImage = 0;
|
||||
item.pszText = DisplayName;
|
||||
item.iItem = ListView_GetItemCount(hServicesListCtrl);
|
||||
item.lParam = 0;
|
||||
ListView_InsertItem(hServicesListCtrl, &item);
|
||||
}
|
||||
}
|
||||
}
|
||||
HeapFree(GetProcessHeap(), 0, pServiceStatus);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else /* exit on failure */
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
|
||||
if (NumServices)
|
||||
{
|
||||
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);
|
||||
|
||||
/* FIXME
|
||||
if (QueryServiceConfig2(ScHandle, SERVICE_CONFIG_FAILURE_ACTIONS, ) == 0)
|
||||
{
|
||||
if (GetLastError() == ERROR_MORE_DATA)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
LoadString(hInst, ( CONDITION ? IDS_YES : IDS_NO), szStatus, 128);
|
||||
item.pszText = szStatus;
|
||||
item.iSubItem = 1;
|
||||
SendMessage(hServicesListCtrl, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
CloseServiceHandle(ScHandle);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue