- Added the properties dialog
authorGed Murphy <gedmurphy@reactos.org>
Fri, 6 Jan 2006 18:28:27 +0000 (18:28 +0000)
committerGed Murphy <gedmurphy@reactos.org>
Fri, 6 Jan 2006 18:28:27 +0000 (18:28 +0000)
- Add an about dialog
- Split up the query code to make it more usable
- Call description from the registry
- Many other code mods

svn path=/trunk/; revision=20616

reactos/subsys/system/servman/En.rc
reactos/subsys/system/servman/about.c [new file with mode: 0644]
reactos/subsys/system/servman/geterror.c [new file with mode: 0644]
reactos/subsys/system/servman/propsheet.c [new file with mode: 0644]
reactos/subsys/system/servman/query.c [new file with mode: 0644]
reactos/subsys/system/servman/resource.h
reactos/subsys/system/servman/servman.c
reactos/subsys/system/servman/servman.h [new file with mode: 0644]
reactos/subsys/system/servman/servman.rc
reactos/subsys/system/servman/servman.xml

index e6184f2..e5b16ac 100644 (file)
@@ -27,6 +27,46 @@ BEGIN
   END\r
 END\r
 \r
+IDD_ABOUTBOX DIALOG DISCARDABLE  22,16,190,182\r
+STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU\r
+CAPTION "About Service Manager"\r
+FONT 8, "Tahoma"\r
+BEGIN\r
+    CONTROL         "Service Manager v0.1\nCopyright (C) 2006\nby Ged Murphy (gedmurphy@gmail.com)",\r
+                    IDC_STATIC,"Static",SS_LEFTNOWORDWRAP | WS_GROUP,48,7,130,26\r
+    DEFPUSHBUTTON   "Close",IDOK,140,162,44,15,WS_GROUP\r
+    ICON            IDI_SM_ICON,IDC_STATIC,12,7,30,20\r
+    EDITTEXT        IDC_LICENSE_EDIT,8,44,174,107,ES_MULTILINE |\r
+                    ES_READONLY | WS_VSCROLL\r
+END\r
+\r
+\r
+IDD_DLG_GENERAL DIALOGEX 6,6,253,225\r
+CAPTION "General"\r
+FONT 8,"MS Sans Serif",0,0\r
+STYLE 0x10CF0000\r
+BEGIN\r
+  CONTROL "Service name:",IDC_STATIC,"Static",0x50000000,4,11,53,11\r
+  CONTROL "Display name:",IDC_STATIC,"Static",0x50000000,4,29,53,11\r
+  CONTROL "Description",IDC_STATIC,"Static",0x50000000,4,51,53,11\r
+  CONTROL "",IDC_SERV_NAME,"Static",0x50000000,70,11,176,11\r
+  CONTROL "",IDC_DISP_NAME,"Static",0x50001000,70,29,176,12\r
+  CONTROL "",IDC_DESCRIPTION,"Static",0x50201000,70,46,176,22\r
+  CONTROL "Path to executable:",IDC_STATIC,"Static",0x50000000,6,73,82,9\r
+  CONTROL "",IDC_STATIC,"Static",0x50001000,6,86,238,12\r
+  CONTROL "Startup type:",IDC_STATIC,"Static",0x50000000,6,108,53,11\r
+  CONTROL "",IDC_START_TYPE,"ComboBox",0x50010003,70,107,176,11\r
+  CONTROL "Service status:",IDC_STATIC,"Static",0x50000000,4,138,53,11\r
+  CONTROL "",IDC_SERV_STATUS,"Static",0x50000000,70,138,176,11\r
+  CONTROL "Start",IDC_START,"Button",0x50010000,6,155,54,15\r
+  CONTROL "Stop",IDC_STOP,"Button",0x50010000,68,155,54,15\r
+  CONTROL "Pause",IDC_PAUSE,"Button",0x50010000,130,155,54,15\r
+  CONTROL "Resume",IDC_RESUME,"Button",0x50010000,192,155,54,15\r
+  CONTROL "You can specify the start parameters that apply when you start the service from here.",IDC_STATIC,"Static",0x50000000,6,177,240,15\r
+  CONTROL "Start parameters",IDC_STATIC,"Static",0x50000000,6,199,53,11\r
+  CONTROL "",IDC_START_PARAM,"Static",0x50001000,70,199,176,11\r
+END\r
+\r
 STRINGTABLE DISCARDABLE\r
 BEGIN\r
   IDS_FIRSTCOLUMN "Name"\r
@@ -48,6 +88,20 @@ STRINGTABLE DISCARDABLE
 BEGIN\r
   IDS_SERVICES_NUM_SERVICES "Num Services: %d"\r
   IDB_START "res/start.bmp"\r
+  IDS_LICENSE "This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.\r\n\r\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.\r\n\r\nYou should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA."\r
+  /*"This program is free software; you can redistribute it "\r
+              "and/or modify it under the terms of the GNU Lesser General "\r
+              "Public License as published by the Free Software Foundation; "\r
+              "either version 2.1 of the License, or (at your option) any "\r
+              "later version.\r\n\r\nThis program is distributed in the hope "\r
+              "that it will be useful, but WITHOUT ANY WARRANTY; without even "\r
+              "the implied warranty of MERCHANTABILITY or FITNESS FOR A "\r
+              "PARTICULAR PURPOSE.  See the GNU General Public License for more "\r
+              "details.\r\n\r\nYou should have received a copy of the GNU "\r
+              "General Public License along with this program; if not, write "\r
+              "to the Free Software Foundation, Inc., 59 Temple Place - Suite "\r
+              "330, Boston, MA  02111-1307, USA." */\r
+  \r
 END\r
 \r
 STRINGTABLE DISCARDABLE\r
diff --git a/reactos/subsys/system/servman/about.c b/reactos/subsys/system/servman/about.c
new file mode 100644 (file)
index 0000000..0bcae71
--- /dev/null
@@ -0,0 +1,35 @@
+#include "servman.h"\r
+\r
+extern HINSTANCE hInstance;\r
+\r
+BOOL CALLBACK\r
+AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
+{\r
+    HWND    hLicenseEditWnd;\r
+    TCHAR    strLicense[0x1000];\r
+\r
+    switch (message)\r
+    {\r
+    case WM_INITDIALOG:\r
+\r
+        hLicenseEditWnd = GetDlgItem(hDlg, IDC_LICENSE_EDIT);\r
+\r
+        LoadString(hInstance, IDS_LICENSE, strLicense, 0x1000);\r
+\r
+        SetWindowText(hLicenseEditWnd, strLicense);\r
+\r
+        return TRUE;\r
+\r
+    case WM_COMMAND:\r
+\r
+        if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))\r
+        {\r
+            EndDialog(hDlg, LOWORD(wParam));\r
+            return TRUE;\r
+        }\r
+\r
+        break;\r
+    }\r
+\r
+    return 0;\r
+}\r
diff --git a/reactos/subsys/system/servman/geterror.c b/reactos/subsys/system/servman/geterror.c
new file mode 100644 (file)
index 0000000..7b8c8fb
--- /dev/null
@@ -0,0 +1,28 @@
+#include "servman.h"\r
+/* temp file for debugging */\r
+\r
+VOID GetError(VOID)\r
+{\r
+    LPVOID lpMsgBuf;\r
+\r
+    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |\r
+                  FORMAT_MESSAGE_FROM_SYSTEM |\r
+                  FORMAT_MESSAGE_IGNORE_INSERTS,\r
+                  NULL,\r
+                  GetLastError(),\r
+                  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */\r
+                  (LPTSTR) &lpMsgBuf,\r
+                   0,\r
+                   NULL );\r
+\r
+        MessageBox(NULL, lpMsgBuf, _T("Error!"), MB_OK | MB_ICONERROR);\r
+\r
+        LocalFree(lpMsgBuf);\r
+}\r
+\r
+\r
+VOID DisplayString(PTCHAR Msg)\r
+{\r
+    MessageBox(NULL, Msg, _T("Error!"), MB_OK | MB_ICONERROR);\r
+\r
+}\r
diff --git a/reactos/subsys/system/servman/propsheet.c b/reactos/subsys/system/servman/propsheet.c
new file mode 100644 (file)
index 0000000..ad8637a
--- /dev/null
@@ -0,0 +1,90 @@
+#include "servman.h"\r
+\r
+extern HINSTANCE hInstance;\r
+\r
+\r
+/* Property page dialog callback */\r
+INT_PTR CALLBACK\r
+GeneralPageProc(HWND hwndDlg,\r
+                UINT uMsg,\r
+                       WPARAM wParam,\r
+                       LPARAM lParam)\r
+{\r
+\r
+    switch (uMsg)\r
+    {\r
+        case WM_INITDIALOG:\r
+\r
+            break;\r
+\r
+        case WM_COMMAND:\r
+            switch(LOWORD(wParam))\r
+            {\r
+                case IDC_START:\r
+                    break;\r
+\r
+                case IDC_STOP:\r
+\r
+                    break;\r
+            }\r
+            break;\r
+\r
+        case WM_DESTROY:\r
+            break;\r
+\r
+        case WM_NOTIFY:\r
+            {\r
+                LPNMHDR lpnm = (LPNMHDR)lParam;\r
+\r
+                switch (lpnm->code)\r
+\r
+                default:\r
+                    break;\r
+            }\r
+            break;\r
+    }\r
+\r
+    return FALSE;\r
+}\r
+\r
+\r
+\r
+static VOID\r
+InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc)\r
+{\r
+  ZeroMemory(psp, sizeof(PROPSHEETPAGE));\r
+  psp->dwSize = sizeof(PROPSHEETPAGE);\r
+  psp->dwFlags = PSP_DEFAULT;\r
+  psp->hInstance = hInstance;\r
+  psp->pszTemplate = MAKEINTRESOURCE(idDlg);\r
+  psp->pfnDlgProc = DlgProc;\r
+}\r
+\r
+\r
+LONG APIENTRY\r
+PropSheets(HWND hwnd)\r
+{\r
+  PROPSHEETHEADER psh;\r
+  PROPSHEETPAGE psp[1];\r
+  TCHAR Caption[256];\r
+\r
+  LoadString(hInstance, IDS_PROP_SHEET, Caption, sizeof(Caption) / sizeof(TCHAR));\r
+\r
+  ZeroMemory(&psh, sizeof(PROPSHEETHEADER));\r
+  psh.dwSize = sizeof(PROPSHEETHEADER);\r
+  psh.dwFlags =  PSH_PROPSHEETPAGE | PSH_PROPTITLE;\r
+  psh.hwndParent = NULL;\r
+  psh.hInstance = hInstance;\r
+  psh.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SM_ICON));\r
+  psh.pszCaption = Caption;\r
+  psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);\r
+  psh.nStartPage = 0;\r
+  psh.ppsp = psp;\r
+\r
+  InitPropSheetPage(&psp[0], IDD_DLG_GENERAL, GeneralPageProc);\r
+  //logon\r
+  //recovery\r
+  //dependancies\r
+\r
+  return (LONG)(PropertySheet(&psh) != -1);\r
+}\r
diff --git a/reactos/subsys/system/servman/query.c b/reactos/subsys/system/servman/query.c
new file mode 100644 (file)
index 0000000..9645835
--- /dev/null
@@ -0,0 +1,328 @@
+#include "servman.h"\r
+\r
+extern HINSTANCE hInstance;\r
+extern HWND hListView;\r
+extern HWND hStatus;\r
+\r
+/* Stores the service array */\r
+ENUM_SERVICE_STATUS_PROCESS *pServiceStatus = NULL;\r
+\r
+\r
+/* free service array */\r
+VOID FreeMemory(VOID)\r
+{\r
+    HeapFree(GetProcessHeap(), 0, pServiceStatus);\r
+}\r
+\r
+\r
+BOOL\r
+RefreshServiceList(VOID)\r
+{\r
+    LV_ITEM item;\r
+    TCHAR szNumServices[32];\r
+    TCHAR szStatus[128];\r
+    DWORD NumServices = 0;\r
+    DWORD Index;\r
+\r
+    NumServices = GetServiceList();\r
+\r
+    if (NumServices)\r
+    {\r
+        HICON hiconItem;     /* icon for list-view items */\r
+        HIMAGELIST hSmall;   /* image list for other views */\r
+        TCHAR buf[40];\r
+\r
+        /* Create the icon image lists */\r
+        hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),\r
+            GetSystemMetrics(SM_CYSMICON), ILC_MASK, 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
+        ImageList_AddIcon(hSmall, hiconItem);\r
+\r
+        ListView_SetImageList(hListView, hSmall, LVSIL_SMALL);\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
+        SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)buf);\r
+\r
+        for (Index = 0; Index < NumServices; Index++)\r
+        {\r
+            HKEY hKey = NULL;\r
+            TCHAR Description[5000];\r
+            DWORD Size = 5000;\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.lParam = 0;\r
+            item.iItem = ListView_InsertItem(hListView, &item);\r
+\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
+            {\r
+                GetError();\r
+                return FALSE;\r
+            }\r
+\r
+            RegQueryValueEx(hKey,\r
+                            _T("Description"),\r
+                            NULL,\r
+                            NULL,\r
+                            (LPBYTE)Description,\r
+                            &Size);\r
+\r
+            item.pszText = Description;\r
+            item.iSubItem = 1;\r
+            SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+\r
+\r
+            /* set the status */\r
+\r
+            if (pServiceStatus[Index].ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)\r
+            {\r
+                LoadString(hInstance, IDS_SERVICES_STATUS_RUNNING, szStatus, 128);\r
+                item.pszText = szStatus;\r
+                item.iSubItem = 2;\r
+                SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+            }\r
+            else\r
+            {\r
+                item.pszText = '\0';\r
+                item.iSubItem = 2;\r
+                SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+            }\r
+         }\r
+    }\r
+\r
+    return TRUE;\r
+}\r
+\r
+\r
+\r
+\r
+DWORD\r
+GetServiceList(VOID)\r
+{\r
+    SC_HANDLE ScHandle;\r
+\r
+    DWORD BytesNeeded = 0;\r
+    DWORD ResumeHandle = 0;\r
+    DWORD NumServices = 0;\r
+\r
+    ScHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);\r
+    if (ScHandle != INVALID_HANDLE_VALUE)\r
+    {\r
+        if (EnumServicesStatusEx(ScHandle,\r
+                                 SC_ENUM_PROCESS_INFO,\r
+                                 SERVICE_WIN32,\r
+                                 SERVICE_STATE_ALL,\r
+                                 (LPBYTE)pServiceStatus,\r
+                                 0, &BytesNeeded,\r
+                                 &NumServices,\r
+                                 &ResumeHandle,\r
+                                 0) == 0)\r
+        {\r
+            /* Call function again if required size was returned */\r
+            if (GetLastError() == ERROR_MORE_DATA)\r
+            {\r
+                /* reserve memory for service info array */\r
+                pServiceStatus = (ENUM_SERVICE_STATUS_PROCESS *) HeapAlloc(GetProcessHeap(), 0, BytesNeeded);\r
+                if (pServiceStatus == NULL)\r
+                               return FALSE;\r
+\r
+                /* fill array with service info */\r
+                if (EnumServicesStatusEx(ScHandle,\r
+                                         SC_ENUM_PROCESS_INFO,\r
+                                         SERVICE_WIN32,\r
+                                         SERVICE_STATE_ALL,\r
+                                         (LPBYTE)pServiceStatus,\r
+                                         BytesNeeded,\r
+                                         &BytesNeeded,\r
+                                         &NumServices,\r
+                                         &ResumeHandle,\r
+                                         0) == 0)\r
+                {\r
+                    HeapFree(GetProcessHeap(), 0, pServiceStatus);\r
+                    return FALSE;\r
+                }\r
+            }\r
+            else /* exit on failure */\r
+            {\r
+                return FALSE;\r
+            }\r
+        }\r
+    }\r
+\r
+    CloseServiceHandle(ScHandle);\r
+\r
+    return NumServices;\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+/*\r
+    //WORD wCodePage;\r
+    //WORD wLangID;\r
+    //SC_HANDLE hService;\r
+    //DWORD dwHandle, dwLen;\r
+    //UINT BufLen;\r
+    //TCHAR* lpData;\r
+    //TCHAR* lpBuffer;\r
+    //TCHAR szStrFileInfo[80];\r
+    //TCHAR FileName[MAX_PATH];\r
+    //LPVOID pvData;\r
+\r
+    //LPSERVICE_FAILURE_ACTIONS pServiceFailureActions = NULL;\r
+    //LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;\r
+\r
+               BytesNeeded = 0;\r
+                hService = OpenService(ScHandle,\r
+                                       pServiceStatus[Index].lpServiceName,\r
+                                       SC_MANAGER_CONNECT);\r
+                if (hService != INVALID_HANDLE_VALUE)\r
+                {\r
+                    / * check if service is required by the system* /\r
+                    if (!QueryServiceConfig2(hService,\r
+                                             SERVICE_CONFIG_FAILURE_ACTIONS,\r
+                                             (LPBYTE)pServiceFailureActions,\r
+                                             0,\r
+                                             &BytesNeeded))\r
+                    {\r
+                        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)\r
+                        {\r
+                            pServiceFailureActions = (LPSERVICE_FAILURE_ACTIONS)\r
+                                HeapAlloc(GetProcessHeap(), 0, BytesNeeded);\r
+                            if (pServiceFailureActions == NULL)\r
+                                           return FALSE;\r
+\r
+                            if (!QueryServiceConfig2(hService,\r
+                                                     SERVICE_CONFIG_FAILURE_ACTIONS,\r
+                                                     (LPBYTE)pServiceFailureActions,\r
+                                                     BytesNeeded,\r
+                                                     &BytesNeeded))\r
+                            {\r
+                                HeapFree(GetProcessHeap(), 0, pServiceFailureActions);\r
+                                return FALSE;\r
+                            }\r
+                        }\r
+                        else / * exit on failure * /\r
+                        {\r
+                            return FALSE;\r
+                        }\r
+                    }\r
+                    if (pServiceFailureActions->cActions)\r
+                    {\r
+                        if (pServiceFailureActions->lpsaActions[0].Type == SC_ACTION_REBOOT)\r
+                        {\r
+                            LoadString(hInstance, IDS_SERVICES_YES, szStatus, 128);\r
+                            item.pszText = szStatus;\r
+                            item.iSubItem = 1;\r
+                            SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+                        }\r
+                    }\r
+\r
+                                       if (pServiceFailureActions != NULL)\r
+                                       {\r
+                                               HeapFree(GetProcessHeap(), 0, pServiceFailureActions);\r
+                                               pServiceFailureActions = NULL;\r
+                                       }\r
+\r
+                    / * get vendor of service binary * /\r
+                    BytesNeeded = 0;\r
+                    if (!QueryServiceConfig(hService, pServiceConfig, 0, &BytesNeeded))\r
+                    {\r
+                        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)\r
+                        {\r
+                            pServiceConfig = (LPQUERY_SERVICE_CONFIG)\r
+                                HeapAlloc(GetProcessHeap(), 0, BytesNeeded);\r
+                            if (pServiceConfig == NULL)\r
+                                           return FALSE;\r
+\r
+                            if (!QueryServiceConfig(hService,\r
+                                                    pServiceConfig,\r
+                                                    BytesNeeded,\r
+                                                    &BytesNeeded))\r
+                            {\r
+                                HeapFree(GetProcessHeap(), 0, pServiceConfig);\r
+                                return FALSE;\r
+                            }\r
+                        }\r
+                        else / * exit on failure * /\r
+                        {\r
+                            return FALSE;\r
+                        }\r
+                    }\r
+\r
+                    memset(&FileName, 0, MAX_PATH);\r
+                    if (_tcscspn(pServiceConfig->lpBinaryPathName, _T("\"")))\r
+                    {\r
+                        _tcsncpy(FileName, pServiceConfig->lpBinaryPathName,\r
+                            _tcscspn(pServiceConfig->lpBinaryPathName, _T(" ")) );\r
+                    }\r
+                    else\r
+                    {\r
+                        _tcscpy(FileName, pServiceConfig->lpBinaryPathName);\r
+                    }\r
+\r
+                                       HeapFree(GetProcessHeap(), 0, pServiceConfig);\r
+                                       pServiceConfig = NULL;\r
+\r
+                                       dwLen = GetFileVersionInfoSize(FileName, &dwHandle);\r
+                    if (dwLen)\r
+                    {\r
+                        lpData = (TCHAR*) HeapAlloc(GetProcessHeap(), 0, dwLen);\r
+                        if (lpData == NULL)\r
+                                       return FALSE;\r
+\r
+                        if (!GetFileVersionInfo (FileName, dwHandle, dwLen, lpData)) {\r
+                                   HeapFree(GetProcessHeap(), 0, lpData);\r
+                                   return FALSE;\r
+                           }\r
+\r
+                        if (VerQueryValue(lpData, _T("\\VarFileInfo\\Translation"), &pvData, (PUINT) &BufLen))\r
+                        {\r
+                            wCodePage = LOWORD(*(DWORD*) pvData);\r
+                            wLangID = HIWORD(*(DWORD*) pvData);\r
+                            wsprintf(szStrFileInfo, _T("StringFileInfo\\%04X%04X\\CompanyName"), wCodePage, wLangID);\r
+                        }\r
+\r
+                        if (VerQueryValue (lpData, szStrFileInfo, (LPVOID) &lpBuffer, (PUINT) &BufLen)) {\r
+                            item.pszText = lpBuffer;\r
+                            item.iSubItem = 2;\r
+                            SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+                        }\r
+                                               HeapFree(GetProcessHeap(), 0, lpData);\r
+                    }\r
+                    else\r
+                    {\r
+                        LoadString(hInstance, IDS_SERVICES_UNKNOWN, szStatus, 128);\r
+                        item.pszText = szStatus;\r
+                        item.iSubItem = 2;\r
+                        SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+                    }\r
+                    CloseServiceHandle(hService);\r
+                }\r
+*/\r
index 049ca05..72ae8e5 100644 (file)
@@ -1,5 +1,10 @@
 #define IDC_STATIC -1\r
 \r
+/* about box info */\r
+#define IDD_ABOUTBOX        200\r
+#define IDC_LICENSE_EDIT    201\r
+#define IDS_LICENSE         202\r
+\r
 #define IDC_SERVLIST        1000\r
 #define IDC_TOOLBAR         1001\r
 #define IDC_STATUSBAR      1002\r
 \r
 #define IDB_START 50\r
 #define IDI_SM_ICON 51\r
+\r
+\r
+\r
+\r
+#define IDS_PROP_SHEET 10000\r
+#define IDD_DLG_GENERAL 10001\r
+#define IDC_SERV_NAME 10041\r
+#define IDC_DISP_NAME 10051\r
+#define IDC_DESCRIPTION 10061\r
+#define IDC_START_TYPE 10101\r
+#define IDC_SERV_STATUS 10121\r
+#define IDC_START 10131\r
+#define IDC_STOP 10141\r
+#define IDC_PAUSE 10151\r
+#define IDC_RESUME 10161\r
+#define IDC_START_PARAM 10191\r
index daf24bc..30f7477 100644 (file)
-#include <windows.h>\r
-#include <stdio.h>\r
-#include <tchar.h>\r
-#include <commctrl.h>\r
-#include "resource.h"\r
+#include "servman.h"\r
+\r
 \r
 const TCHAR ClassName[] = _T("ServiceManager");\r
 \r
 HINSTANCE hInstance;\r
+HWND hMainWnd;\r
 HWND hListView;\r
 HWND hStatus;\r
 \r
 \r
-void\r
-GetServices ( void )\r
-{\r
-    LV_ITEM item;\r
-    WORD wCodePage;\r
-    WORD wLangID;\r
-    SC_HANDLE ScHandle;\r
-    SC_HANDLE hService;\r
-    DWORD BytesNeeded = 0;\r
-    DWORD ResumeHandle = 0;\r
-    DWORD NumServices = 0;\r
-    DWORD dwHandle, dwLen;\r
-    size_t Index;\r
-    UINT BufLen;\r
-    TCHAR szStatus[128];\r
-    TCHAR* lpData;\r
-    TCHAR* lpBuffer;\r
-    TCHAR szStrFileInfo[80];\r
-    TCHAR FileName[MAX_PATH];\r
-    TCHAR szNumServices[32];\r
-    LPVOID pvData;\r
-\r
-    LPSERVICE_FAILURE_ACTIONS pServiceFailureActions = NULL;\r
-    LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;\r
-    ENUM_SERVICE_STATUS_PROCESS *pServiceStatus = NULL;\r
-\r
-    ScHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);\r
-    if (ScHandle != INVALID_HANDLE_VALUE)\r
-    {\r
-        if (EnumServicesStatusEx(ScHandle,\r
-                                 SC_ENUM_PROCESS_INFO,\r
-                                 SERVICE_WIN32,\r
-                                 SERVICE_STATE_ALL,\r
-                                 (LPBYTE)pServiceStatus,\r
-                                 0, &BytesNeeded,\r
-                                 &NumServices,\r
-                                 &ResumeHandle,\r
-                                 0) == 0)\r
-        {\r
-            /* Call function again if required size was returned */\r
-            if (GetLastError() == ERROR_MORE_DATA)\r
-            {\r
-                /* reserve memory for service info array */\r
-                pServiceStatus = (ENUM_SERVICE_STATUS_PROCESS *) HeapAlloc(GetProcessHeap(), 0, BytesNeeded);\r
-                if (pServiceStatus == NULL)\r
-                               return;\r
-\r
-                /* fill array with service info */\r
-                if (EnumServicesStatusEx(ScHandle,\r
-                                         SC_ENUM_PROCESS_INFO,\r
-                                         SERVICE_WIN32,\r
-                                         SERVICE_STATE_ALL,\r
-                                         (LPBYTE)pServiceStatus,\r
-                                         BytesNeeded,\r
-                                         &BytesNeeded,\r
-                                         &NumServices,\r
-                                         &ResumeHandle,\r
-                                         0) == 0)\r
-                {\r
-                    HeapFree(GetProcessHeap(), 0, pServiceStatus);\r
-                    return;\r
-                }\r
-            }\r
-            else /* exit on failure */\r
-            {\r
-                return;\r
-            }\r
-        }\r
-\r
-        if (NumServices)\r
-        {\r
-            HICON hiconItem;     // icon for list-view items\r
-            HIMAGELIST hSmall;   // image list for other views\r
-            TCHAR buf[40];\r
-\r
-            /* Create the icon image lists */\r
-            hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),\r
-                GetSystemMetrics(SM_CYSMICON), ILC_MASK, 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
-            ImageList_AddIcon(hSmall, hiconItem);\r
-\r
-            ListView_SetImageList(hListView, hSmall, LVSIL_SMALL);\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
-            SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)buf);\r
-\r
-            for (Index = 0; Index < NumServices; Index++)\r
-            {\r
-                memset(&item, 0, 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.lParam = 0;\r
-                item.iItem = ListView_InsertItem(hListView, &item);\r
-\r
-                BytesNeeded = 0;\r
-                hService = OpenService(ScHandle,\r
-                                       pServiceStatus[Index].lpServiceName,\r
-                                       SC_MANAGER_CONNECT);\r
-                if (hService != INVALID_HANDLE_VALUE)\r
-                {\r
-                    /* check if service is required by the system*/\r
-                    if (!QueryServiceConfig2(hService,\r
-                                             SERVICE_CONFIG_FAILURE_ACTIONS,\r
-                                             (LPBYTE)pServiceFailureActions,\r
-                                             0,\r
-                                             &BytesNeeded))\r
-                    {\r
-                        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)\r
-                        {\r
-                            pServiceFailureActions = (LPSERVICE_FAILURE_ACTIONS)\r
-                                HeapAlloc(GetProcessHeap(), 0, BytesNeeded);\r
-                            if (pServiceFailureActions == NULL)\r
-                                           return;\r
-\r
-                            if (!QueryServiceConfig2(hService,\r
-                                                     SERVICE_CONFIG_FAILURE_ACTIONS,\r
-                                                     (LPBYTE)pServiceFailureActions,\r
-                                                     BytesNeeded,\r
-                                                     &BytesNeeded))\r
-                            {\r
-                                HeapFree(GetProcessHeap(), 0, pServiceFailureActions);\r
-                                return;\r
-                            }\r
-                        }\r
-                        else /* exit on failure */\r
-                        {\r
-                            return;\r
-                        }\r
-                    }\r
-                    if (pServiceFailureActions->cActions)\r
-                    {\r
-                        if (pServiceFailureActions->lpsaActions[0].Type == SC_ACTION_REBOOT)\r
-                        {\r
-                            LoadString(hInstance, IDS_SERVICES_YES, szStatus, 128);\r
-                            item.pszText = szStatus;\r
-                            item.iSubItem = 1;\r
-                            SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
-                        }\r
-                    }\r
-\r
-                                       if (pServiceFailureActions != NULL)\r
-                                       {\r
-                                               HeapFree(GetProcessHeap(), 0, pServiceFailureActions);\r
-                                               pServiceFailureActions = NULL;\r
-                                       }\r
-\r
-                    /* get vendor of service binary */\r
-                    BytesNeeded = 0;\r
-                    if (!QueryServiceConfig(hService, pServiceConfig, 0, &BytesNeeded))\r
-                    {\r
-                        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)\r
-                        {\r
-                            pServiceConfig = (LPQUERY_SERVICE_CONFIG)\r
-                                HeapAlloc(GetProcessHeap(), 0, BytesNeeded);\r
-                            if (pServiceConfig == NULL)\r
-                                           return;\r
-\r
-                            if (!QueryServiceConfig(hService,\r
-                                                    pServiceConfig,\r
-                                                    BytesNeeded,\r
-                                                    &BytesNeeded))\r
-                            {\r
-                                HeapFree(GetProcessHeap(), 0, pServiceConfig);\r
-                                return;\r
-                            }\r
-                        }\r
-                        else /* exit on failure */\r
-                        {\r
-                            return;\r
-                        }\r
-                    }\r
-\r
-                    memset(&FileName, 0, MAX_PATH);\r
-                    if (_tcscspn(pServiceConfig->lpBinaryPathName, _T("\"")))\r
-                    {\r
-                        _tcsncpy(FileName, pServiceConfig->lpBinaryPathName,\r
-                            _tcscspn(pServiceConfig->lpBinaryPathName, _T(" ")) );\r
-                    }\r
-                    else\r
-                    {\r
-                        _tcscpy(FileName, pServiceConfig->lpBinaryPathName);\r
-                    }\r
-\r
-                                       HeapFree(GetProcessHeap(), 0, pServiceConfig);\r
-                                       pServiceConfig = NULL;\r
-\r
-                                       dwLen = GetFileVersionInfoSize(FileName, &dwHandle);\r
-                    if (dwLen)\r
-                    {\r
-                        lpData = (TCHAR*) HeapAlloc(GetProcessHeap(), 0, dwLen);\r
-                        if (lpData == NULL)\r
-                                       return;\r
-\r
-                        if (!GetFileVersionInfo (FileName, dwHandle, dwLen, lpData)) {\r
-                                   HeapFree(GetProcessHeap(), 0, lpData);\r
-                                   return;\r
-                           }\r
-\r
-                        if (VerQueryValue(lpData, _T("\\VarFileInfo\\Translation"), &pvData, (PUINT) &BufLen))\r
-                        {\r
-                            wCodePage = LOWORD(*(DWORD*) pvData);\r
-                            wLangID = HIWORD(*(DWORD*) pvData);\r
-                            wsprintf(szStrFileInfo, _T("StringFileInfo\\%04X%04X\\CompanyName"), wCodePage, wLangID);\r
-                        }\r
-\r
-                        if (VerQueryValue (lpData, szStrFileInfo, (LPVOID) &lpBuffer, (PUINT) &BufLen)) {\r
-                            item.pszText = lpBuffer;\r
-                            item.iSubItem = 2;\r
-                            SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
-                        }\r
-                                               HeapFree(GetProcessHeap(), 0, lpData);\r
-                    }\r
-                    else\r
-                    {\r
-                        LoadString(hInstance, IDS_SERVICES_UNKNOWN, szStatus, 128);\r
-                        item.pszText = szStatus;\r
-                        item.iSubItem = 2;\r
-                        SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
-                    }\r
-                    CloseServiceHandle(hService);\r
-                }\r
-\r
-                if (pServiceStatus[Index].ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)\r
-                {\r
-                    LoadString(hInstance, IDS_SERVICES_STATUS_RUNNING, szStatus, 128);\r
-                    item.pszText = szStatus;\r
-                    item.iSubItem = 2;\r
-                    SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
-                }\r
-                else\r
-                {\r
-                    item.pszText = '\0';\r
-                    item.iSubItem = 2;\r
-                    SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
-                }\r
-\r
-            }\r
-        }\r
-\r
-        HeapFree(GetProcessHeap(), 0, pServiceStatus);\r
-        CloseServiceHandle(ScHandle);\r
-    }\r
-\r
-\r
-}\r
-\r
-\r
-\r
 LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)\r
 {\r
        switch(msg)\r
@@ -285,7 +29,6 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
             LVCOLUMN lvc = { 0 };\r
             //LVITEM   lv  = { 0 };\r
 \r
-            //GetClientRect(hwnd, &rc);\r
             hListView = CreateWindow(WC_LISTVIEW,\r
                                      NULL,\r
                                      WS_CHILD | WS_VISIBLE | LVS_REPORT | WS_BORDER | LVS_EDITLABELS,\r
@@ -309,13 +52,13 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
             ListView_InsertColumn(hListView, 0, &lvc);\r
 \r
             lvc.iSubItem = 1;\r
-            lvc.cx       = 150;\r
+            lvc.cx       = 260;\r
             LoadString(hInstance, IDS_SECONDCOLUMN, szTemp, 256);\r
             lvc.pszText  = szTemp;\r
             ListView_InsertColumn(hListView, 1, &lvc);\r
 \r
             lvc.iSubItem = 2;\r
-            lvc.cx       = 80;\r
+            lvc.cx       = 75;\r
             LoadString(hInstance, IDS_THIRDCOLUMN, szTemp, 256);\r
             lvc.pszText  = szTemp;\r
             ListView_InsertColumn(hListView, 2, &lvc);\r
@@ -332,7 +75,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
             lvc.pszText  = szTemp;\r
             ListView_InsertColumn(hListView, 4, &lvc);\r
 \r
-                       // Create Toolbar\r
+                       /* Create Toolbar */\r
                        hTool = CreateWindowEx(0,\r
                                    TOOLBARCLASSNAME,\r
                                    NULL,\r
@@ -396,12 +139,14 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                                      hInstance,\r
                                      NULL);\r
             if(hStatus == NULL)\r
-                               MessageBox(hwnd, _T("Could not create status bar."), _T("Error"), MB_OK | MB_ICONERROR);\r
+                               MessageBox(hwnd, _T("Could not create status bar."),\r
+                           _T("Error!"), MB_OK | MB_ICONERROR);\r
 \r
                        SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);\r
 \r
                        /* populate the list view with all services */\r
-                       GetServices();\r
+                       if (! RefreshServiceList() )\r
+                GetError();\r
                }\r
                break;\r
                case WM_SIZE:\r
@@ -410,11 +155,11 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                        RECT rcTool;\r
                        int iToolHeight;\r
 \r
-                       HWND hStatus;\r
+                       //HWND hStatus;\r
                        RECT rcStatus;\r
                        int iStatusHeight;\r
 \r
-                       HWND hListView;\r
+                       //HWND hListView;\r
                        int lvHeight;\r
                        RECT rcClient;\r
 \r
@@ -490,14 +235,14 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                 }\r
                 break;\r
 \r
-                // Process other notifications here.\r
-\r
                 default:\r
                 break;\r
             }\r
         break;\r
 \r
                case WM_CLOSE:\r
+            /* free the service array */\r
+            FreeMemory();\r
                        DestroyWindow(hwnd);\r
                break;\r
                case WM_DESTROY:\r
@@ -529,13 +274,18 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                 break;\r
 \r
                 case ID_PROP:\r
+                    PropSheets(hwnd);\r
                 break;\r
 \r
                 case ID_VIEW_CUSTOMIZE:\r
                 break;\r
 \r
                 case ID_HELP_ABOUT:\r
-                break;\r
+                    DialogBox(GetModuleHandle(NULL),\r
+                              MAKEINTRESOURCE(IDD_ABOUTBOX),\r
+                              hwnd,\r
+                              AboutDialogProc);\r
+                 break;\r
 \r
                 case ID_EXPORT:\r
                 break;\r
@@ -554,7 +304,6 @@ int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance,
        LPSTR lpCmdLine, int nCmdShow)\r
 {\r
        WNDCLASSEX wc;\r
-       HWND hwnd;\r
        MSG Msg;\r
        BOOL bRet;\r
 \r
@@ -568,7 +317,7 @@ int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance,
        wc.cbClsExtra    = 0;\r
        wc.cbWndExtra    = 0;\r
        wc.hInstance     = hInstance;\r
-       wc.hIcon                 = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_SM_ICON));\r
+       wc.hIcon                 = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SM_ICON));\r
        wc.hCursor               = LoadCursor(NULL, IDC_ARROW);\r
        wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);\r
        wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MAINMENU);\r
@@ -583,7 +332,7 @@ int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance,
                return 0;\r
        }\r
 \r
-       hwnd = CreateWindowEx(\r
+       hMainWnd = CreateWindowEx(\r
                0,\r
                ClassName,\r
                _T("ReactOS Service Manager"),\r
@@ -591,15 +340,15 @@ int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance,
                CW_USEDEFAULT, CW_USEDEFAULT, 700, 500,\r
                NULL, NULL, hInstance, NULL);\r
 \r
-       if(hwnd == NULL)\r
+       if(hMainWnd == NULL)\r
        {\r
                MessageBox(NULL, _T("Window Creation Failed!"), _T("Error!"),\r
                        MB_ICONEXCLAMATION | MB_OK);\r
                return 0;\r
        }\r
 \r
-       ShowWindow(hwnd, nCmdShow);\r
-       UpdateWindow(hwnd);\r
+       ShowWindow(hMainWnd, nCmdShow);\r
+       UpdateWindow(hMainWnd);\r
 \r
     while( (bRet = GetMessage( &Msg, NULL, 0, 0 )) != 0)\r
     {\r
diff --git a/reactos/subsys/system/servman/servman.h b/reactos/subsys/system/servman/servman.h
new file mode 100644 (file)
index 0000000..23ad45e
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef __SERVMAN_H\r
+#define __SERVMAN_H\r
+\r
+\r
+#include <windows.h>\r
+#include <stdio.h>\r
+#include <tchar.h>\r
+#include <commctrl.h>\r
+#include "resource.h"\r
+\r
+BOOL RefreshServiceList(VOID);\r
+\r
+BOOL CALLBACK\r
+AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
+\r
+VOID GetError(VOID);\r
+VOID FreeMemory(VOID);\r
+VOID DisplayString(PTCHAR);\r
+\r
+LONG APIENTRY\r
+PropSheets(HWND hwnd);\r
+\r
+DWORD GetServiceList(VOID);\r
+\r
+\r
+#endif /* __SERVMAN_H */\r
index 3af5355..0b0e22c 100644 (file)
@@ -6,7 +6,7 @@
 #define REACTOS_STR_FILE_DESCRIPTION   "ReactOS Service Manager\0"\r
 #define REACTOS_STR_INTERNAL_NAME      "services\0"\r
 #define REACTOS_STR_ORIGINAL_FILENAME  "services.exe\0"\r
-#include <reactos/version.rc>\r
+//#include <reactos/version.rc>\r
 \r
 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US\r
 \r
index 8960377..930231a 100644 (file)
        <library>comctl32</library>\r
        <library>shell32</library>\r
        <compilationunit name="unit.c">\r
+               <file>about.c</file>\r
+               <file>geterror.c</file>\r
+               <file>propsheet.c</file>\r
+               <file>query.c</file>\r
                <file>servman.c</file>\r
        </compilationunit>\r
        <file>servman.rc</file>\r