list services with EnumServicesStatusEx instead of reading them from registry
Modified: trunk/reactos/subsys/system/msconfig/De.rc
Modified: trunk/reactos/subsys/system/msconfig/En.rc
Modified: trunk/reactos/subsys/system/msconfig/resource.h
Modified: trunk/reactos/subsys/system/msconfig/srvpage.c

Modified: trunk/reactos/subsys/system/msconfig/De.rc
--- trunk/reactos/subsys/system/msconfig/De.rc	2005-11-10 23:02:14 UTC (rev 19127)
+++ trunk/reactos/subsys/system/msconfig/De.rc	2005-11-11 01:05:23 UTC (rev 19128)
@@ -50,6 +50,7 @@
 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 @@
     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
+

Modified: trunk/reactos/subsys/system/msconfig/En.rc
--- trunk/reactos/subsys/system/msconfig/En.rc	2005-11-10 23:02:14 UTC (rev 19127)
+++ trunk/reactos/subsys/system/msconfig/En.rc	2005-11-11 01:05:23 UTC (rev 19128)
@@ -50,6 +50,7 @@
 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 @@
     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

Modified: trunk/reactos/subsys/system/msconfig/resource.h
--- trunk/reactos/subsys/system/msconfig/resource.h	2005-11-10 23:02:14 UTC (rev 19127)
+++ trunk/reactos/subsys/system/msconfig/resource.h	2005-11-11 01:05:23 UTC (rev 19128)
@@ -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 */

Modified: trunk/reactos/subsys/system/msconfig/srvpage.c
--- 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);
+    }        
+
+
 }