[ros-diffs] [gedmurphy] 28670: - implement setting the service description - fix deleting of a service

gedmurphy at svn.reactos.org gedmurphy at svn.reactos.org
Thu Aug 30 14:27:12 CEST 2007


Author: gedmurphy
Date: Thu Aug 30 16:27:11 2007
New Revision: 28670

URL: http://svn.reactos.org/svn/reactos?rev=28670&view=rev
Log:
- implement setting the service description
- fix deleting of a service

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

Modified: trunk/reactos/base/applications/mscutils/servman/create.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils/servman/create.c?rev=28670&r1=28669&r2=28670&view=diff
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/create.c (original)
+++ trunk/reactos/base/applications/mscutils/servman/create.c Thu Aug 30 16:27:11 2007
@@ -60,10 +60,10 @@
         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,

Modified: trunk/reactos/base/applications/mscutils/servman/delete.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils/servman/delete.c?rev=28670&r1=28669&r2=28670&view=diff
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/delete.c (original)
+++ trunk/reactos/base/applications/mscutils/servman/delete.c Thu Aug 30 16:27:11 2007
@@ -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 at gmail.com>
+ * COPYRIGHT:   Copyright 2006-2007 Ged Murphy <gedmurphy at reactos.org>
  *
  */
 
@@ -15,42 +15,30 @@
 {
     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;
+            }
+
+            CloseServiceHandle(hSc);
+        }
+
+        CloseServiceHandle(hSCManager);
     }
 
-    /* get a handle to the service requested for deleting */
-    hSc = OpenService(hSCManager,
-                      Info->pCurrentService->lpServiceName,
-                      DELETE);
-    if (hSc == NULL)
-    {
-        GetError();
-        CloseServiceHandle(hSCManager);
-        return FALSE;
-    }
-
-    /* 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 @@
 {
     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);
+                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);
+                }
 
-            SendMessage(hDlg,
-                        WM_SETICON,
-                        ICON_SMALL,
-                        (LPARAM)hIcon);
+                SendDlgItemMessage(hDlg,
+                                   IDC_DEL_NAME,
+                                   WM_SETTEXT,
+                                   0,
+                                   (LPARAM)Info->pCurrentService->lpDisplayName);
 
-            SendDlgItemMessage(hDlg,
-                               IDC_DEL_NAME,
-                               WM_SETTEXT,
-                               0,
-                               (LPARAM)Info->pCurrentService->lpDisplayName);
+                lpDescription = GetServiceDescription(Info->pCurrentService->lpServiceName);
+                if (lpDescription)
+                {
+                    SendDlgItemMessage(hDlg,
+                                       IDC_DEL_DESC,
+                                       WM_SETTEXT,
+                                       0,
+                                       (LPARAM)lpDescription);
+                    HeapFree(ProcessHeap,
+                             0,
+                             lpDescription);
+                }
 
+                return TRUE;
+            }
 
-            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;
+            return FALSE;
         }
 
         case WM_COMMAND:
@@ -120,8 +121,6 @@
                     if (DoDeleteService(Info, hDlg))
                         (void)ListView_DeleteItem(Info->hListView,
                                                   Info->SelectedItem);
-
-                    DestroyIcon(hIcon);
                     EndDialog(hDlg,
                               LOWORD(wParam));
                     return TRUE;
@@ -129,7 +128,6 @@
 
                 case IDCANCEL:
                 {
-                    DestroyIcon(hIcon);
                     EndDialog(hDlg,
                               LOWORD(wParam));
                     return TRUE;

Modified: trunk/reactos/base/applications/mscutils/servman/precomp.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils/servman/precomp.h?rev=28670&r1=28669&r2=28670&view=diff
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/precomp.h (original)
+++ trunk/reactos/base/applications/mscutils/servman/precomp.h Thu Aug 30 16:27:11 2007
@@ -88,6 +88,7 @@
 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);

Modified: trunk/reactos/base/applications/mscutils/servman/query.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils/servman/query.c?rev=28670&r1=28669&r2=28670&view=diff
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/query.c (original)
+++ trunk/reactos/base/applications/mscutils/servman/query.c Thu Aug 30 16:27:11 2007
@@ -210,6 +210,53 @@
     return lpDescription;
 }
 
+
+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

Modified: trunk/reactos/base/applications/mscutils/servman/servman.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils/servman/servman.c?rev=28670&r1=28669&r2=28670&view=diff
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/servman.c (original)
+++ trunk/reactos/base/applications/mscutils/servman/servman.c Thu Aug 30 16:27:11 2007
@@ -64,6 +64,3 @@
 
     return Ret;
 }
-
-
-




More information about the Ros-diffs mailing list