From 53281cd6016a8d15ee9367a4ccbd01957859d732 Mon Sep 17 00:00:00 2001 From: Ged Murphy Date: Sat, 2 Jan 2010 12:10:14 +0000 Subject: [PATCH] [SERVMAN] Quick fix for bug 5076, this should stop if from crashing. Stopping services is disabled at the moment svn path=/trunk/; revision=44881 --- .../mscutils/servman/dependencies_tv2.c | 6 +- .../applications/mscutils/servman/precomp.h | 5 ++ .../mscutils/servman/propsheet_depends.c | 12 ++-- .../base/applications/mscutils/servman/stop.c | 72 +++++++------------ 4 files changed, 40 insertions(+), 55 deletions(-) diff --git a/reactos/base/applications/mscutils/servman/dependencies_tv2.c b/reactos/base/applications/mscutils/servman/dependencies_tv2.c index 3bbf490c5b0..2cd1bcadc84 100644 --- a/reactos/base/applications/mscutils/servman/dependencies_tv2.c +++ b/reactos/base/applications/mscutils/servman/dependencies_tv2.c @@ -10,8 +10,8 @@ #include "precomp.h" -static BOOL -HasDependantServices(LPWSTR lpServiceName) +BOOL +TV2_HasDependantServices(LPWSTR lpServiceName) { HANDLE hSCManager; HANDLE hService; @@ -136,7 +136,7 @@ TV2_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo, for (i = 0; i < count; i++) { /* Does this item need a +/- box? */ - bHasChildren = HasDependantServices(lpServiceStatus[i].lpServiceName); + bHasChildren = TV2_HasDependantServices(lpServiceStatus[i].lpServiceName); /* Add it */ AddItemToTreeView(pDlgInfo->hDependsTreeView2, diff --git a/reactos/base/applications/mscutils/servman/precomp.h b/reactos/base/applications/mscutils/servman/precomp.h index b278327c669..b50e566c0b1 100644 --- a/reactos/base/applications/mscutils/servman/precomp.h +++ b/reactos/base/applications/mscutils/servman/precomp.h @@ -23,6 +23,10 @@ #define LVSTARTUP 3 #define LVLOGONAS 4 +#define IMAGE_UNKNOWN 0 +#define IMAGE_SERVICE 1 +#define IMAGE_DRIVER 2 + typedef struct _MAIN_WND_INFO { HWND hMainWnd; @@ -130,6 +134,7 @@ VOID TV1_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo, HTREEITEM hParent, LPTS /* tv2_dependencies */ BOOL TV2_Initialize(PSERVICEPROPSHEET pDlgInfo, LPTSTR lpServiceName); VOID TV2_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo, HTREEITEM hParent, LPTSTR lpServiceName); +BOOL TV2_HasDependantServices(LPWSTR lpServiceName); LONG APIENTRY OpenPropSheet(PMAIN_WND_INFO Info); diff --git a/reactos/base/applications/mscutils/servman/propsheet_depends.c b/reactos/base/applications/mscutils/servman/propsheet_depends.c index 70814355ed3..2a7fe8fd701 100644 --- a/reactos/base/applications/mscutils/servman/propsheet_depends.c +++ b/reactos/base/applications/mscutils/servman/propsheet_depends.c @@ -34,19 +34,19 @@ AddItemToTreeView(HWND hTreeView, { case SERVICE_WIN32_OWN_PROCESS: case SERVICE_WIN32_SHARE_PROCESS: - tvi.iImage = 1; - tvi.iSelectedImage = 1; + tvi.iImage = IMAGE_SERVICE; + tvi.iSelectedImage = IMAGE_SERVICE; break; case SERVICE_KERNEL_DRIVER: case SERVICE_FILE_SYSTEM_DRIVER: - tvi.iImage = 2; - tvi.iSelectedImage = 2; + tvi.iImage = IMAGE_DRIVER; + tvi.iSelectedImage = IMAGE_DRIVER; break; default: - tvi.iImage = 0; - tvi.iSelectedImage = 0; + tvi.iImage = IMAGE_UNKNOWN; + tvi.iSelectedImage = IMAGE_UNKNOWN; break; } diff --git a/reactos/base/applications/mscutils/servman/stop.c b/reactos/base/applications/mscutils/servman/stop.c index 5a5fef6c3c2..412ccae20b0 100644 --- a/reactos/base/applications/mscutils/servman/stop.c +++ b/reactos/base/applications/mscutils/servman/stop.c @@ -11,16 +11,16 @@ static BOOL -StopService(PSTOP_INFO pStopInfo, - SC_HANDLE hService) +StopService(PMAIN_WND_INFO pInfo, + LPWSTR lpServiceName) { - SERVICE_STATUS_PROCESS ServiceStatus; - DWORD dwBytesNeeded; - DWORD dwStartTime; - DWORD dwTimeout; - HWND hProgDlg; + //SERVICE_STATUS_PROCESS ServiceStatus; + //DWORD dwBytesNeeded; + //DWORD dwStartTime; + // DWORD dwTimeout; + //HWND hProgDlg; BOOL bRet = FALSE; - +/* dwStartTime = GetTickCount(); dwTimeout = 30000; // 30 secs @@ -47,7 +47,7 @@ StopService(PSTOP_INFO pStopInfo, { if (GetTickCount() - dwStartTime > dwTimeout) { - /* We exceeded our max wait time, give up */ + We exceeded our max wait time, give up break; } } @@ -63,13 +63,13 @@ StopService(PSTOP_INFO pStopInfo, Sleep(500); DestroyWindow(hProgDlg); } - +*/ return bRet; } static BOOL -StopDependentServices(PSTOP_INFO pStopInfo, - SC_HANDLE hService) +StopDependantServices(PMAIN_WND_INFO pInfo, + LPWSTR lpServiceName) { //LPENUM_SERVICE_STATUS lpDependencies; //SC_HANDLE hDepService; @@ -118,53 +118,33 @@ StopDependentServices(PSTOP_INFO pStopInfo, BOOL DoStop(PMAIN_WND_INFO pInfo) { - STOP_INFO stopInfo; - //SC_HANDLE hSCManager; - SC_HANDLE hService = NULL; BOOL bRet = FALSE; if (pInfo) { - //stopInfo.pInfo = pInfo; - - if (TRUE /*HasDependentServices(pInfo->pCurrentService->lpServiceName)*/) + /* Does this service have anything which depends on it? */ + if (TV2_HasDependantServices(pInfo->pCurrentService->lpServiceName)) { - INT ret = DialogBoxParam(hInstance, - MAKEINTRESOURCE(IDD_DLG_DEPEND_STOP), - pInfo->hMainWnd, - StopDependsDialogProc, - (LPARAM)&stopInfo); - if (ret == IDOK) + /* It does, list them and ask the user if they want to stop them as well */ + if (DialogBoxParam(hInstance, + MAKEINTRESOURCE(IDD_DLG_DEPEND_STOP), + pInfo->hMainWnd, + StopDependsDialogProc, + (LPARAM)&pInfo) == IDOK) { - if (StopDependentServices(&stopInfo, hService)) + /* Stop all the dependany services */ + if (StopDependantServices(pInfo, pInfo->pCurrentService->lpServiceName)) { - bRet = StopService(&stopInfo, hService); + /* Finally stop the requested service */ + bRet = StopService(pInfo, pInfo->pCurrentService->lpServiceName); } } } else { - bRet = StopService(&stopInfo, hService); + /* No dependants, just stop the service */ + bRet = StopService(pInfo, pInfo->pCurrentService->lpServiceName); } -/* - hSCManager = OpenSCManager(NULL, - NULL, - SC_MANAGER_ALL_ACCESS); - if (hSCManager) - { - hService = OpenService(hSCManager, - pInfo->pCurrentService->lpServiceName, - SERVICE_STOP | SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS); - if (hService) - { - stopInfo.hSCManager = hSCManager; - stopInfo.hMainService = hService; - - CloseServiceHandle(hService); - } - - CloseServiceHandle(hSCManager); - }*/ } return bRet;