ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dependencies_tv2.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:     ReactOS Services
00003  * LICENSE:     GPL - See COPYING in the top level directory
00004  * FILE:        base/applications/mscutils/servman/tv2_dependencies.c
00005  * PURPOSE:     Helper functions for service dependents
00006  * COPYRIGHT:   Copyright 2009 Ged Murphy <gedmurphy@reactos.org>
00007  *
00008  */
00009 
00010 #include "precomp.h"
00011 
00012 
00013 BOOL
00014 TV2_HasDependantServices(LPWSTR lpServiceName)
00015 {
00016     HANDLE hSCManager;
00017     HANDLE hService;
00018     DWORD dwBytesNeeded, dwCount;
00019     BOOL bRet = FALSE;
00020 
00021     hSCManager = OpenSCManager(NULL,
00022                                NULL,
00023                                SC_MANAGER_ALL_ACCESS);
00024     if (hSCManager)
00025     {
00026         hService = OpenService(hSCManager,
00027                                lpServiceName,
00028                                SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS);
00029         if (hService)
00030         {
00031             /* Does this have any dependencies? */
00032             if (!EnumDependentServices(hService,
00033                                        SERVICE_STATE_ALL,
00034                                        NULL,
00035                                        0,
00036                                        &dwBytesNeeded,
00037                                        &dwCount))
00038             {
00039                  if (GetLastError() == ERROR_MORE_DATA)
00040                  {
00041                      /* It does, return TRUE */
00042                      bRet = TRUE;
00043                  }
00044             }
00045         }
00046 
00047         CloseServiceHandle(hSCManager);
00048     }
00049 
00050     return bRet;
00051 }
00052 
00053 
00054 LPENUM_SERVICE_STATUS
00055 TV2_GetDependants(LPWSTR lpServiceName,
00056                   LPDWORD lpdwCount)
00057 {
00058     SC_HANDLE hSCManager;
00059     SC_HANDLE hService;
00060     LPENUM_SERVICE_STATUSW lpDependencies = NULL;
00061     DWORD dwBytesNeeded;
00062     DWORD dwCount;
00063 
00064     /* Set the first items in each tree view */
00065     hSCManager = OpenSCManagerW(NULL,
00066                                 NULL,
00067                                 SC_MANAGER_ALL_ACCESS);
00068     if (hSCManager)
00069     {
00070         hService = OpenServiceW(hSCManager,
00071                                 lpServiceName,
00072                                 SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS | SERVICE_QUERY_CONFIG);
00073         if (hService)
00074         {
00075             /* Does this have any dependencies? */
00076             if (!EnumDependentServicesW(hService,
00077                                         SERVICE_STATE_ALL,
00078                                         NULL,
00079                                         0,
00080                                         &dwBytesNeeded,
00081                                         &dwCount) &&
00082                 GetLastError() == ERROR_MORE_DATA)
00083             {
00084                 lpDependencies = (LPENUM_SERVICE_STATUSW)HeapAlloc(GetProcessHeap(),
00085                                                                   0,
00086                                                                   dwBytesNeeded);
00087                 if (lpDependencies)
00088                 {
00089                     /* Get the list of dependents */
00090                     if (EnumDependentServicesW(hService,
00091                                                SERVICE_STATE_ALL,
00092                                                lpDependencies,
00093                                                dwBytesNeeded,
00094                                                &dwBytesNeeded,
00095                                                &dwCount))
00096                     {
00097                         /* Set the count */
00098                         *lpdwCount = dwCount;
00099                     }
00100                     else
00101                     {
00102                         HeapFree(ProcessHeap,
00103                                  0,
00104                                  lpDependencies);
00105 
00106                         lpDependencies = NULL;
00107                     }
00108                 }
00109             }
00110 
00111             CloseServiceHandle(hService);
00112         }
00113 
00114         CloseServiceHandle(hSCManager);
00115     }
00116 
00117     return lpDependencies;
00118 }
00119 
00120 
00121 VOID
00122 TV2_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo,
00123                         HTREEITEM hParent,
00124                         LPTSTR lpServiceName)
00125 {
00126 
00127     LPENUM_SERVICE_STATUSW lpServiceStatus;
00128     LPTSTR lpNoDepends;
00129     DWORD count, i;
00130     BOOL bHasChildren;
00131 
00132     /* Get a list of service dependents */
00133     lpServiceStatus = TV2_GetDependants(lpServiceName, &count);
00134     if (lpServiceStatus)
00135     {
00136         for (i = 0; i < count; i++)
00137         {
00138             /* Does this item need a +/- box? */
00139             bHasChildren = TV2_HasDependantServices(lpServiceStatus[i].lpServiceName);
00140 
00141             /* Add it */
00142             AddItemToTreeView(pDlgInfo->hDependsTreeView2,
00143                               hParent,
00144                               lpServiceStatus[i].lpDisplayName,
00145                               lpServiceStatus[i].lpServiceName,
00146                               lpServiceStatus[i].ServiceStatus.dwServiceType,
00147                               bHasChildren);
00148         }
00149 
00150         HeapFree(GetProcessHeap(),
00151                  0,
00152                  lpServiceStatus);
00153     }
00154     else
00155     {
00156         /* If there is no parent, set the tree to 'no dependencies' */
00157         if (!hParent)
00158         {
00159             /* Load the 'No dependencies' string */
00160             AllocAndLoadString(&lpNoDepends, hInstance, IDS_NO_DEPENDS);
00161 
00162             AddItemToTreeView(pDlgInfo->hDependsTreeView2,
00163                               NULL,
00164                               lpNoDepends,
00165                               NULL,
00166                               0,
00167                               FALSE);
00168 
00169             HeapFree(ProcessHeap,
00170                      0,
00171                      lpNoDepends);
00172 
00173             /* Disable the window */
00174             EnableWindow(pDlgInfo->hDependsTreeView2, FALSE);
00175         }
00176     }
00177 }
00178 
00179 BOOL
00180 TV2_Initialize(PSERVICEPROPSHEET pDlgInfo,
00181                LPTSTR lpServiceName)
00182 {
00183     BOOL bRet = FALSE;
00184 
00185     /* Accociate the imagelist with TV2 */
00186     pDlgInfo->hDependsTreeView2 = GetDlgItem(pDlgInfo->hDependsWnd, IDC_DEPEND_TREE2);
00187     if (!pDlgInfo->hDependsTreeView2)
00188     {
00189         ImageList_Destroy(pDlgInfo->hDependsImageList);
00190         pDlgInfo->hDependsImageList = NULL;
00191         return FALSE;
00192     }
00193     (void)TreeView_SetImageList(pDlgInfo->hDependsTreeView2,
00194                                 pDlgInfo->hDependsImageList,
00195                                 TVSIL_NORMAL);
00196 
00197     /* Set the first items in the control */
00198     TV2_AddDependantsToTree(pDlgInfo, NULL, lpServiceName);
00199 
00200     return bRet;
00201 }

Generated on Sat May 26 2012 04:15:54 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.