- implement setting the service description
authorGed Murphy <gedmurphy@reactos.org>
Thu, 30 Aug 2007 12:27:11 +0000 (12:27 +0000)
committerGed Murphy <gedmurphy@reactos.org>
Thu, 30 Aug 2007 12:27:11 +0000 (12:27 +0000)
- fix deleting of a service

svn path=/trunk/; revision=28670

reactos/base/applications/mscutils/servman/create.c
reactos/base/applications/mscutils/servman/delete.c
reactos/base/applications/mscutils/servman/precomp.h
reactos/base/applications/mscutils/servman/query.c
reactos/base/applications/mscutils/servman/servman.c

index 1601ab0..433b802 100644 (file)
@@ -60,10 +60,10 @@ DoCreate(PCREATE_DATA Data)
         return FALSE;
     }
 
-    /* Set the service description in the registry
-     * CreateService does not do this for us */
-    //SetDescription(Data->ServiceName,
-    //               Data->Description);
+    /* Set the service description as CreateService
+       does not do this for us */
+    SetServiceDescription(Data->ServiceName,
+                          Data->Description);
 
     /* report success to user */
     LoadString(hInstance,
index e6e732e..cf5c855 100644 (file)
@@ -1,9 +1,9 @@
 /*
  * PROJECT:     ReactOS Services
  * LICENSE:     GPL - See COPYING in the top level directory
- * FILE:        base/system/servman/delete.c
+ * FILE:        base/applications/mscutils/servman/delete.c
  * PURPOSE:     Delete an existing service
- * COPYRIGHT:   Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
+ * COPYRIGHT:   Copyright 2006-2007 Ged Murphy <gedmurphy@reactos.org>
  *
  */
 
@@ -15,42 +15,30 @@ DoDeleteService(PMAIN_WND_INFO Info,
 {
     SC_HANDLE hSCManager;
     SC_HANDLE hSc;
+    BOOL bRet = FALSE;
 
-    /* open handle to the SCM */
     hSCManager = OpenSCManager(NULL,
                                NULL,
                                SC_MANAGER_ALL_ACCESS);
-    if (hSCManager == NULL)
+    if (hSCManager)
     {
-        GetError();
-        return FALSE;
-    }
+        hSc = OpenService(hSCManager,
+                          Info->pCurrentService->lpServiceName,
+                          DELETE);
+        if (hSc)
+        {
+            if (DeleteService(hSc))
+            {
+                bRet = TRUE;
+            }
 
-    /* get a handle to the service requested for deleting */
-    hSc = OpenService(hSCManager,
-                      Info->pCurrentService->lpServiceName,
-                      DELETE);
-    if (hSc == NULL)
-    {
-        GetError();
-        CloseServiceHandle(hSCManager);
-        return FALSE;
-    }
+            CloseServiceHandle(hSc);
+        }
 
-    /* delete the service opened */
-    if (! DeleteService(hSc))
-    {
-        GetError();
         CloseServiceHandle(hSCManager);
-        CloseServiceHandle(hSc);
-        return FALSE;
     }
 
-
-    CloseServiceHandle(hSCManager);
-    CloseServiceHandle(hSc);
-
-    return TRUE;
+    return bRet;
 }
 
 
@@ -62,53 +50,66 @@ DeleteDialogProc(HWND hDlg,
 {
     PMAIN_WND_INFO Info = NULL;
     HICON hIcon = NULL;
-    TCHAR Buf[1000];
-    LVITEM item;
+
+    /* Get the window context */
+    Info = (PMAIN_WND_INFO)GetWindowLongPtr(hDlg,
+                                            GWLP_USERDATA);
+    if (Info == NULL && message != WM_INITDIALOG)
+    {
+        return FALSE;
+    }
 
     switch (message)
     {
         case WM_INITDIALOG:
         {
+            LPTSTR lpDescription;
+
             Info = (PMAIN_WND_INFO)lParam;
+            if (Info != NULL)
+            {
+                SetWindowLongPtr(hDlg,
+                                 GWLP_USERDATA,
+                                 (LONG_PTR)Info);
+
+                hIcon = (HICON)LoadImage(hInstance,
+                                         MAKEINTRESOURCE(IDI_SM_ICON),
+                                         IMAGE_ICON,
+                                         16,
+                                         16,
+                                         0);
+                if (hIcon)
+                {
+                    SendMessage(hDlg,
+                                WM_SETICON,
+                                ICON_SMALL,
+                                (LPARAM)hIcon);
+                    DestroyIcon(hIcon);
+                }
+
+                SendDlgItemMessage(hDlg,
+                                   IDC_DEL_NAME,
+                                   WM_SETTEXT,
+                                   0,
+                                   (LPARAM)Info->pCurrentService->lpDisplayName);
 
-            hIcon = (HICON) LoadImage(hInstance,
-                              MAKEINTRESOURCE(IDI_SM_ICON),
-                              IMAGE_ICON,
-                              16,
-                              16,
-                              0);
-
-            SendMessage(hDlg,
-                        WM_SETICON,
-                        ICON_SMALL,
-                        (LPARAM)hIcon);
-
-            SendDlgItemMessage(hDlg,
-                               IDC_DEL_NAME,
-                               WM_SETTEXT,
-                               0,
-                               (LPARAM)Info->pCurrentService->lpDisplayName);
-
-
-            item.mask = LVIF_TEXT;
-            item.iItem = Info->SelectedItem;
-            item.iSubItem = 1;
-            item.pszText = Buf;
-            item.cchTextMax = sizeof(Buf);
-            SendMessage(Info->hListView,
-                        LVM_GETITEM,
-                        0,
-                        (LPARAM)&item);
-
-            SendDlgItemMessage(hDlg,
-                               IDC_DEL_DESC,
-                               WM_SETTEXT,
-                               0,
-                               (LPARAM)Buf);
-
-            SetFocus(GetDlgItem(hDlg, IDCANCEL));
-
-            return TRUE;
+                lpDescription = GetServiceDescription(Info->pCurrentService->lpServiceName);
+                if (lpDescription)
+                {
+                    SendDlgItemMessage(hDlg,
+                                       IDC_DEL_DESC,
+                                       WM_SETTEXT,
+                                       0,
+                                       (LPARAM)lpDescription);
+                    HeapFree(ProcessHeap,
+                             0,
+                             lpDescription);
+                }
+
+                return TRUE;
+            }
+
+            return FALSE;
         }
 
         case WM_COMMAND:
@@ -120,8 +121,6 @@ DeleteDialogProc(HWND hDlg,
                     if (DoDeleteService(Info, hDlg))
                         (void)ListView_DeleteItem(Info->hListView,
                                                   Info->SelectedItem);
-
-                    DestroyIcon(hIcon);
                     EndDialog(hDlg,
                               LOWORD(wParam));
                     return TRUE;
@@ -129,7 +128,6 @@ DeleteDialogProc(HWND hDlg,
 
                 case IDCANCEL:
                 {
-                    DestroyIcon(hIcon);
                     EndDialog(hDlg,
                               LOWORD(wParam));
                     return TRUE;
index bc5f503..8e7ebff 100644 (file)
@@ -88,6 +88,7 @@ ENUM_SERVICE_STATUS_PROCESS* GetSelectedService(PMAIN_WND_INFO Info);
 LPQUERY_SERVICE_CONFIG GetServiceConfig(LPTSTR lpServiceName);
 BOOL SetServiceConfig(LPQUERY_SERVICE_CONFIG pServiceConfig, LPTSTR lpServiceName, LPTSTR lpPassword);
 LPTSTR GetServiceDescription(LPTSTR lpServiceName);
+BOOL SetServiceDescription(LPTSTR lpServiceName, LPTSTR lpDescription);
 LPTSTR GetExecutablePath(LPTSTR lpServiceName);
 BOOL RefreshServiceList(PMAIN_WND_INFO Info);
 BOOL UpdateServiceStatus(ENUM_SERVICE_STATUS_PROCESS* pService);
index 9bdbfb7..d14347f 100644 (file)
@@ -211,6 +211,53 @@ cleanup:
 }
 
 
+BOOL
+SetServiceDescription(LPTSTR lpServiceName,
+                      LPTSTR lpDescription)
+{
+    SC_HANDLE hSCManager;
+    SC_HANDLE hSc;
+    SC_LOCK scLock;
+    SERVICE_DESCRIPTION ServiceDescription;
+    BOOL bRet = FALSE;
+
+    hSCManager = OpenSCManager(NULL,
+                               NULL,
+                               SC_MANAGER_LOCK);
+    if (hSCManager)
+    {
+        scLock = LockServiceDatabase(hSCManager);
+        if (scLock)
+        {
+            hSc = OpenService(hSCManager,
+                              lpServiceName,
+                              SERVICE_CHANGE_CONFIG);
+            if (hSc)
+            {
+                ServiceDescription.lpDescription = lpDescription;
+
+                if (ChangeServiceConfig2(hSc,
+                                         SERVICE_CONFIG_DESCRIPTION,
+                                         &ServiceDescription))
+                {
+                    bRet = TRUE;
+                }
+
+                CloseServiceHandle(hSc);
+            }
+
+            UnlockServiceDatabase(scLock);
+        }
+
+        CloseServiceHandle(hSCManager);
+    }
+
+    if (!bRet)
+        GetError();
+
+    return bRet;
+}
+
 
 BOOL
 GetServiceList(PMAIN_WND_INFO Info,