fix msvc warnings
[reactos.git] / reactos / subsys / system / servman / query.c
index 9645835..523b223 100644 (file)
@@ -1,3 +1,12 @@
+/*\r
+ * PROJECT:     ReactOS Services\r
+ * LICENSE:     GPL - See COPYING in the top level directory\r
+ * FILE:        subsys/system/servman/query.c\r
+ * PURPOSE:     Query service information\r
+ * COPYRIGHT:   Copyright 2005 Ged Murphy <gedmurphy@gmail.com>\r
+ *               \r
+ */\r
+\r
 #include "servman.h"\r
 \r
 extern HINSTANCE hInstance;\r
 #include "servman.h"\r
 \r
 extern HINSTANCE hInstance;\r
@@ -18,11 +27,14 @@ VOID FreeMemory(VOID)
 BOOL\r
 RefreshServiceList(VOID)\r
 {\r
 BOOL\r
 RefreshServiceList(VOID)\r
 {\r
-    LV_ITEM item;\r
+    LVITEM item;\r
     TCHAR szNumServices[32];\r
     TCHAR szStatus[128];\r
     DWORD NumServices = 0;\r
     DWORD Index;\r
     TCHAR szNumServices[32];\r
     TCHAR szStatus[128];\r
     DWORD NumServices = 0;\r
     DWORD Index;\r
+    LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");\r
+\r
+    ListView_DeleteAllItems(hListView);\r
 \r
     NumServices = GetServiceList();\r
 \r
 \r
     NumServices = GetServiceList();\r
 \r
@@ -30,11 +42,11 @@ RefreshServiceList(VOID)
     {\r
         HICON hiconItem;     /* icon for list-view items */\r
         HIMAGELIST hSmall;   /* image list for other views */\r
     {\r
         HICON hiconItem;     /* icon for list-view items */\r
         HIMAGELIST hSmall;   /* image list for other views */\r
-        TCHAR buf[40];\r
+        TCHAR buf[300];\r
 \r
         /* Create the icon image lists */\r
         hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),\r
 \r
         /* Create the icon image lists */\r
         hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),\r
-            GetSystemMetrics(SM_CYSMICON), ILC_MASK, 1, 1);\r
+        GetSystemMetrics(SM_CYSMICON), ILC_MASK | ILC_COLOR16, 1, 1);\r
 \r
         /* Add an icon to each image list */\r
         hiconItem = LoadImage(hInstance, MAKEINTRESOURCE(IDI_SM_ICON), IMAGE_ICON, 16, 16, 0);\r
 \r
         /* Add an icon to each image list */\r
         hiconItem = LoadImage(hInstance, MAKEINTRESOURCE(IDI_SM_ICON), IMAGE_ICON, 16, 16, 0);\r
@@ -44,51 +56,90 @@ RefreshServiceList(VOID)
 \r
         /* set the number of services in the status bar */\r
         LoadString(hInstance, IDS_SERVICES_NUM_SERVICES, szNumServices, 32);\r
 \r
         /* set the number of services in the status bar */\r
         LoadString(hInstance, IDS_SERVICES_NUM_SERVICES, szNumServices, 32);\r
-        _stprintf(buf, szNumServices, NumServices);\r
+        _sntprintf(buf, 300, szNumServices, NumServices);\r
         SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)buf);\r
 \r
         SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)buf);\r
 \r
+\r
         for (Index = 0; Index < NumServices; Index++)\r
         {\r
             HKEY hKey = NULL;\r
         for (Index = 0; Index < NumServices; Index++)\r
         {\r
             HKEY hKey = NULL;\r
-            TCHAR Description[5000];\r
-            DWORD Size = 5000;\r
+            LPTSTR Description = NULL;\r
+            LONG ret;\r
+            LPTSTR LogOnAs = NULL;\r
+            DWORD StartUp = 0;\r
+            DWORD dwValueSize;\r
+\r
+             /* open the registry key for the service */\r
+            _sntprintf(buf, 300, Path,\r
+                      pServiceStatus[Index].lpServiceName);\r
+\r
+            if( RegOpenKeyEx(HKEY_LOCAL_MACHINE,\r
+                             buf,\r
+                             0,\r
+                             KEY_READ,\r
+                             &hKey) != ERROR_SUCCESS)\r
+            {\r
+                GetError();\r
+                return FALSE;\r
+            }\r
+\r
 \r
             /* set the display name */\r
 \r
             ZeroMemory(&item, sizeof(LV_ITEM));\r
             item.mask = LVIF_TEXT;\r
 \r
             /* set the display name */\r
 \r
             ZeroMemory(&item, sizeof(LV_ITEM));\r
             item.mask = LVIF_TEXT;\r
-            //item.iImage = 0;\r
             item.pszText = pServiceStatus[Index].lpDisplayName;\r
             item.iItem = ListView_GetItemCount(hListView);\r
             item.pszText = pServiceStatus[Index].lpDisplayName;\r
             item.iItem = ListView_GetItemCount(hListView);\r
-            item.lParam = 0;\r
             item.iItem = ListView_InsertItem(hListView, &item);\r
 \r
             item.iItem = ListView_InsertItem(hListView, &item);\r
 \r
+            \r
 \r
             /* set the description */\r
 \r
             /* set the description */\r
-\r
-            _stprintf(buf, _T("System\\CurrentControlSet\\Services\\%s"),\r
-                      pServiceStatus[Index].lpServiceName);\r
-\r
-            if( RegOpenKeyEx(HKEY_LOCAL_MACHINE,\r
-                             buf,\r
-                             0,\r
-                             KEY_READ,\r
-                             &hKey) != ERROR_SUCCESS)\r
+            dwValueSize = 0;\r
+            ret = RegQueryValueEx(hKey,\r
+                                _T("Description"),\r
+                                NULL,\r
+                                NULL,\r
+                                NULL,\r
+                                &dwValueSize);\r
+            if (ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND)\r
             {\r
             {\r
-                GetError();\r
+                RegCloseKey(hKey);\r
                 return FALSE;\r
             }\r
                 return FALSE;\r
             }\r
+            \r
+            if (ret != ERROR_FILE_NOT_FOUND)\r
+            {\r
+                Description = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwValueSize);\r
+                if (Description == NULL)\r
+                {\r
+                    RegCloseKey(hKey);\r
+                    return FALSE;\r
+                }\r
+                if(RegQueryValueEx(hKey,\r
+                                   _T("Description"),\r
+                                   NULL,\r
+                                   NULL,\r
+                                   (LPBYTE)Description,\r
+                                   &dwValueSize))\r
+                {\r
+                    HeapFree(GetProcessHeap(), 0, Description);\r
+                    RegCloseKey(hKey);\r
+                    return FALSE;\r
+                }\r
 \r
 \r
-            RegQueryValueEx(hKey,\r
-                            _T("Description"),\r
-                            NULL,\r
-                            NULL,\r
-                            (LPBYTE)Description,\r
-                            &Size);\r
+                item.pszText = Description;\r
+                item.iSubItem = 1;\r
+                SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
 \r
 \r
-            item.pszText = Description;\r
-            item.iSubItem = 1;\r
-            SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+                HeapFree(GetProcessHeap(), 0, Description);\r
+            }\r
+            else\r
+            {\r
+                item.pszText = '\0';\r
+                item.iSubItem = 1;\r
+                SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+            }            \r
 \r
 \r
             /* set the status */\r
 \r
 \r
             /* set the status */\r
@@ -106,8 +157,87 @@ RefreshServiceList(VOID)
                 item.iSubItem = 2;\r
                 SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
             }\r
                 item.iSubItem = 2;\r
                 SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
             }\r
-         }\r
-    }\r
+\r
+            /* set the startup type */\r
+\r
+            dwValueSize = sizeof(DWORD);\r
+            if (RegQueryValueEx(hKey,\r
+                                _T("Start"),\r
+                                NULL,\r
+                                NULL,\r
+                                (LPBYTE)&StartUp,\r
+                                &dwValueSize))\r
+            {\r
+                RegCloseKey(hKey);\r
+                return FALSE;\r
+            }\r
+\r
+            if (StartUp == 0x02)\r
+            {\r
+                LoadString(hInstance, IDS_SERVICES_AUTO, szStatus, 128);\r
+                item.pszText = szStatus;\r
+                item.iSubItem = 3;\r
+                SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+            }\r
+            else if (StartUp == 0x03)\r
+            {\r
+                LoadString(hInstance, IDS_SERVICES_MAN, szStatus, 128);\r
+                item.pszText = szStatus;\r
+                item.iSubItem = 3;\r
+                SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+            }\r
+            else if (StartUp == 0x04)\r
+            {\r
+                LoadString(hInstance, IDS_SERVICES_DIS, szStatus, 128);\r
+                item.pszText = szStatus;\r
+                item.iSubItem = 3;\r
+                SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+            }\r
+\r
+\r
+\r
+            /* set Log On As */\r
+\r
+            dwValueSize = 0;\r
+            if (RegQueryValueEx(hKey,\r
+                                _T("ObjectName"),\r
+                                NULL,\r
+                                NULL,\r
+                                NULL,\r
+                                &dwValueSize))\r
+            {\r
+                RegCloseKey(hKey);\r
+                return FALSE;\r
+            }\r
+            \r
+            LogOnAs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwValueSize);\r
+            if (LogOnAs == NULL)\r
+            {\r
+                RegCloseKey(hKey);\r
+                return FALSE;\r
+            }\r
+            if(RegQueryValueEx(hKey,\r
+                               _T("ObjectName"),\r
+                               NULL,\r
+                               NULL,\r
+                               (LPBYTE)LogOnAs,\r
+                               &dwValueSize))\r
+            {\r
+                HeapFree(GetProcessHeap(), 0, LogOnAs);\r
+                RegCloseKey(hKey);\r
+                return FALSE;\r
+            }\r
+\r
+            item.pszText = LogOnAs;\r
+            item.iSubItem = 4;\r
+            SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+\r
+            HeapFree(GetProcessHeap(), 0, LogOnAs);\r
+\r
+            RegCloseKey(hKey);\r
+\r
+        }\r
+    } \r
 \r
     return TRUE;\r
 }\r
 \r
     return TRUE;\r
 }\r