[SERVMAN]

Quick fix for bug 5076, this should stop if from crashing.
Stopping services is disabled at the moment

svn path=/trunk/; revision=44881
This commit is contained in:
Ged Murphy 2010-01-02 12:10:14 +00:00
parent 2c793a902d
commit 53281cd601
4 changed files with 40 additions and 55 deletions

View file

@ -10,8 +10,8 @@
#include "precomp.h" #include "precomp.h"
static BOOL BOOL
HasDependantServices(LPWSTR lpServiceName) TV2_HasDependantServices(LPWSTR lpServiceName)
{ {
HANDLE hSCManager; HANDLE hSCManager;
HANDLE hService; HANDLE hService;
@ -136,7 +136,7 @@ TV2_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo,
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
/* Does this item need a +/- box? */ /* Does this item need a +/- box? */
bHasChildren = HasDependantServices(lpServiceStatus[i].lpServiceName); bHasChildren = TV2_HasDependantServices(lpServiceStatus[i].lpServiceName);
/* Add it */ /* Add it */
AddItemToTreeView(pDlgInfo->hDependsTreeView2, AddItemToTreeView(pDlgInfo->hDependsTreeView2,

View file

@ -23,6 +23,10 @@
#define LVSTARTUP 3 #define LVSTARTUP 3
#define LVLOGONAS 4 #define LVLOGONAS 4
#define IMAGE_UNKNOWN 0
#define IMAGE_SERVICE 1
#define IMAGE_DRIVER 2
typedef struct _MAIN_WND_INFO typedef struct _MAIN_WND_INFO
{ {
HWND hMainWnd; HWND hMainWnd;
@ -130,6 +134,7 @@ VOID TV1_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo, HTREEITEM hParent, LPTS
/* tv2_dependencies */ /* tv2_dependencies */
BOOL TV2_Initialize(PSERVICEPROPSHEET pDlgInfo, LPTSTR lpServiceName); BOOL TV2_Initialize(PSERVICEPROPSHEET pDlgInfo, LPTSTR lpServiceName);
VOID TV2_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo, HTREEITEM hParent, LPTSTR lpServiceName); VOID TV2_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo, HTREEITEM hParent, LPTSTR lpServiceName);
BOOL TV2_HasDependantServices(LPWSTR lpServiceName);
LONG APIENTRY OpenPropSheet(PMAIN_WND_INFO Info); LONG APIENTRY OpenPropSheet(PMAIN_WND_INFO Info);

View file

@ -34,19 +34,19 @@ AddItemToTreeView(HWND hTreeView,
{ {
case SERVICE_WIN32_OWN_PROCESS: case SERVICE_WIN32_OWN_PROCESS:
case SERVICE_WIN32_SHARE_PROCESS: case SERVICE_WIN32_SHARE_PROCESS:
tvi.iImage = 1; tvi.iImage = IMAGE_SERVICE;
tvi.iSelectedImage = 1; tvi.iSelectedImage = IMAGE_SERVICE;
break; break;
case SERVICE_KERNEL_DRIVER: case SERVICE_KERNEL_DRIVER:
case SERVICE_FILE_SYSTEM_DRIVER: case SERVICE_FILE_SYSTEM_DRIVER:
tvi.iImage = 2; tvi.iImage = IMAGE_DRIVER;
tvi.iSelectedImage = 2; tvi.iSelectedImage = IMAGE_DRIVER;
break; break;
default: default:
tvi.iImage = 0; tvi.iImage = IMAGE_UNKNOWN;
tvi.iSelectedImage = 0; tvi.iSelectedImage = IMAGE_UNKNOWN;
break; break;
} }

View file

@ -11,16 +11,16 @@
static BOOL static BOOL
StopService(PSTOP_INFO pStopInfo, StopService(PMAIN_WND_INFO pInfo,
SC_HANDLE hService) LPWSTR lpServiceName)
{ {
SERVICE_STATUS_PROCESS ServiceStatus; //SERVICE_STATUS_PROCESS ServiceStatus;
DWORD dwBytesNeeded; //DWORD dwBytesNeeded;
DWORD dwStartTime; //DWORD dwStartTime;
DWORD dwTimeout; // DWORD dwTimeout;
HWND hProgDlg; //HWND hProgDlg;
BOOL bRet = FALSE; BOOL bRet = FALSE;
/*
dwStartTime = GetTickCount(); dwStartTime = GetTickCount();
dwTimeout = 30000; // 30 secs dwTimeout = 30000; // 30 secs
@ -47,7 +47,7 @@ StopService(PSTOP_INFO pStopInfo,
{ {
if (GetTickCount() - dwStartTime > dwTimeout) if (GetTickCount() - dwStartTime > dwTimeout)
{ {
/* We exceeded our max wait time, give up */ We exceeded our max wait time, give up
break; break;
} }
} }
@ -63,13 +63,13 @@ StopService(PSTOP_INFO pStopInfo,
Sleep(500); Sleep(500);
DestroyWindow(hProgDlg); DestroyWindow(hProgDlg);
} }
*/
return bRet; return bRet;
} }
static BOOL static BOOL
StopDependentServices(PSTOP_INFO pStopInfo, StopDependantServices(PMAIN_WND_INFO pInfo,
SC_HANDLE hService) LPWSTR lpServiceName)
{ {
//LPENUM_SERVICE_STATUS lpDependencies; //LPENUM_SERVICE_STATUS lpDependencies;
//SC_HANDLE hDepService; //SC_HANDLE hDepService;
@ -118,53 +118,33 @@ StopDependentServices(PSTOP_INFO pStopInfo,
BOOL BOOL
DoStop(PMAIN_WND_INFO pInfo) DoStop(PMAIN_WND_INFO pInfo)
{ {
STOP_INFO stopInfo;
//SC_HANDLE hSCManager;
SC_HANDLE hService = NULL;
BOOL bRet = FALSE; BOOL bRet = FALSE;
if (pInfo) if (pInfo)
{ {
//stopInfo.pInfo = pInfo; /* Does this service have anything which depends on it? */
if (TV2_HasDependantServices(pInfo->pCurrentService->lpServiceName))
if (TRUE /*HasDependentServices(pInfo->pCurrentService->lpServiceName)*/)
{ {
INT ret = DialogBoxParam(hInstance, /* It does, list them and ask the user if they want to stop them as well */
MAKEINTRESOURCE(IDD_DLG_DEPEND_STOP), if (DialogBoxParam(hInstance,
pInfo->hMainWnd, MAKEINTRESOURCE(IDD_DLG_DEPEND_STOP),
StopDependsDialogProc, pInfo->hMainWnd,
(LPARAM)&stopInfo); StopDependsDialogProc,
if (ret == IDOK) (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 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; return bRet;