--- trunk/reactos/subsys/system/msconfig/srvpage.c 2005-11-10 23:02:14 UTC (rev 19127)
+++ trunk/reactos/subsys/system/msconfig/srvpage.c 2005-11-11 01:05:23 UTC (rev 19128)
@@ -34,16 +34,22 @@
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 @@
void
GetServices ( void )
{
- HKEY hKey, hSubKey;
- DWORD dwSubKeys, dwKeyLength;
- DWORD dwType, dwDataLength;
+ LV_ITEM item;
+ SC_HANDLE ScHandle;
+ DWORD BufSize = 0;
+ DWORD BytesNeeded = 0;
+ DWORD ResumeHandle = 0;
+ DWORD NumServices = 0;
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;
+ 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)
+ HeapFree(GetProcessHeap(), 0, pServiceStatus);
+ return;
+ }
+ }
+ else /* exit on failure */
+ {
+ return;
+ }
+ }
+
+ 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)
{
- 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);
- }
- }
+
}
}
+ 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);
+
}
}
- RegCloseKey(hKey);
- }
+
+ CloseServiceHandle(ScHandle);
+ }
+
+
}