Author: gedmurphy
Date: Wed Apr 29 13:53:10 2009
New Revision: 40728
URL:
http://svn.reactos.org/svn/reactos?rev=40728&view=rev
Log:
- Add the list of dependencies to the listbox so we know what else will be stopping
- Restructure the stop code
Modified:
trunk/reactos/base/applications/mscutils/servman/lang/en-US.rc
trunk/reactos/base/applications/mscutils/servman/resource.h
trunk/reactos/base/applications/mscutils/servman/start.c
trunk/reactos/base/applications/mscutils/servman/stop.c
Modified: trunk/reactos/base/applications/mscutils/servman/lang/en-US.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/lang/en-US.rc [iso-8859-1]
(original)
+++ trunk/reactos/base/applications/mscutils/servman/lang/en-US.rc [iso-8859-1] Wed Apr 29
13:53:10 2009
@@ -154,7 +154,7 @@
BEGIN
ICON IDI_WARNING, IDC_STATIC, 10, 8, 24, 22
LTEXT "", IDC_STOP_DEPENDS, 40, 8, 170, 25
- EDITTEXT IDC_DEL_DESC, 15, 40, 210, 60, WS_CHILD | WS_VISIBLE | WS_EX_STATICEDGE |
ES_MULTILINE | ES_READONLY
+ LISTBOX IDC_STOP_DEPENDS_LB, 15, 40, 210, 70, WS_CHILD | WS_VISIBLE | WS_EX_STATICEDGE
| LBS_NOSEL
LTEXT "Do you want to stop these services?",IDC_STATIC, 15, 110, 150, 10
DEFPUSHBUTTON "Yes", IDOK, 60, 129, 54, 14
PUSHBUTTON "No", IDCANCEL, 120, 129, 54, 14
Modified: trunk/reactos/base/applications/mscutils/servman/resource.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/resource.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mscutils/servman/resource.h [iso-8859-1] Wed Apr 29
13:53:10 2009
@@ -178,4 +178,5 @@
/* stop dependencies */
#define IDD_DLG_DEPEND_STOP 12000
#define IDC_STOP_DEPENDS 12001
-#define IDS_STOP_DEPENDS 12001
+#define IDS_STOP_DEPENDS 12002
+#define IDC_STOP_DEPENDS_LB 12003
Modified: trunk/reactos/base/applications/mscutils/servman/start.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/start.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mscutils/servman/start.c [iso-8859-1] Wed Apr 29
13:53:10 2009
@@ -23,22 +23,22 @@
DWORD dwMaxWait;
BOOL bRet = FALSE;
- hSCManager = OpenSCManagerW(NULL,
- NULL,
- SC_MANAGER_ALL_ACCESS);
+ hSCManager = OpenSCManager(NULL,
+ NULL,
+ SC_MANAGER_ALL_ACCESS);
if (!hSCManager)
{
return FALSE;
}
- hService = OpenServiceW(hSCManager,
- Info->pCurrentService->lpServiceName,
- SERVICE_START | SERVICE_QUERY_STATUS);
+ hService = OpenService(hSCManager,
+ Info->pCurrentService->lpServiceName,
+ SERVICE_START | SERVICE_QUERY_STATUS);
if (hService)
{
- bRet = StartServiceW(hService,
- 0,
- NULL);
+ bRet = StartService(hService,
+ 0,
+ NULL);
if (!bRet && GetLastError() == ERROR_SERVICE_ALREADY_RUNNING)
{
bRet = TRUE;
Modified: trunk/reactos/base/applications/mscutils/servman/stop.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/stop.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mscutils/servman/stop.c [iso-8859-1] Wed Apr 29
13:53:10 2009
@@ -9,8 +9,16 @@
#include "precomp.h"
+typedef struct _STOP_INFO
+{
+ PMAIN_WND_INFO pInfo;
+ SC_HANDLE hSCManager;
+ SC_HANDLE hMainService;
+} STOP_INFO, *PSTOP_INFO;
+
+
static BOOL
-StopService(PMAIN_WND_INFO pInfo,
+StopService(PSTOP_INFO pStopInfo,
SC_HANDLE hService)
{
SERVICE_STATUS_PROCESS ServiceStatus;
@@ -23,8 +31,8 @@
dwStartTime = GetTickCount();
dwTimeout = 30000; // 30 secs
- hProgDlg = CreateProgressDialog(pInfo->hMainWnd,
- pInfo->pCurrentService->lpServiceName,
+ hProgDlg = CreateProgressDialog(pStopInfo->pInfo->hMainWnd,
+
pStopInfo->pInfo->pCurrentService->lpServiceName,
IDS_PROGRESS_INFO_STOP);
if (hProgDlg)
{
@@ -67,8 +75,7 @@
}
static LPENUM_SERVICE_STATUS
-GetDependentServices(PMAIN_WND_INFO pInfo,
- SC_HANDLE hService,
+GetDependentServices(SC_HANDLE hService,
LPDWORD lpdwCount)
{
LPENUM_SERVICE_STATUS lpDependencies;
@@ -88,7 +95,7 @@
else
{
if (GetLastError() != ERROR_MORE_DATA)
- return NULL; // Unexpected error
+ return NULL; /* Unexpected error */
lpDependencies = (LPENUM_SERVICE_STATUS)HeapAlloc(GetProcessHeap(),
0,
@@ -120,8 +127,7 @@
}
static BOOL
-StopDependentServices(PMAIN_WND_INFO pInfo,
- SC_HANDLE hSCManager,
+StopDependentServices(PSTOP_INFO pStopInfo,
SC_HANDLE hService)
{
LPENUM_SERVICE_STATUS lpDependencies;
@@ -129,7 +135,7 @@
DWORD dwCount;
BOOL bRet = FALSE;
- lpDependencies = GetDependentServices(pInfo, hService, &dwCount);
+ lpDependencies = GetDependentServices(hService, &dwCount);
if (lpDependencies)
{
LPENUM_SERVICE_STATUS lpEnumServiceStatus;
@@ -139,12 +145,12 @@
{
lpEnumServiceStatus = &lpDependencies[i];
- hDepService = OpenService(hSCManager,
+ hDepService = OpenService(pStopInfo->hSCManager,
lpEnumServiceStatus->lpServiceName,
SERVICE_STOP | SERVICE_QUERY_STATUS);
if (hDepService)
{
- bRet = StopService(pInfo, hDepService);
+ bRet = StopService(pStopInfo, hDepService);
CloseServiceHandle(hDepService);
@@ -165,57 +171,46 @@
}
static BOOL
-HasDependentServices(PMAIN_WND_INFO pInfo)
+HasDependentServices(SC_HANDLE hService)
+{
+ DWORD dwBytesNeeded, dwCount;
+ BOOL bRet = FALSE;
+
+ if (hService)
+ {
+ if (!EnumDependentServices(hService,
+ SERVICE_ACTIVE,
+ NULL,
+ 0,
+ &dwBytesNeeded,
+ &dwCount))
+ {
+ if (GetLastError() == ERROR_MORE_DATA)
+ bRet = TRUE;
+ }
+ }
+
+ return bRet;
+}
+
+static BOOL
+DoInitDependsDialog(PSTOP_INFO pStopInfo,
+ HWND hDlg)
{
SC_HANDLE hSCManager;
SC_HANDLE hService;
- DWORD dwBytesNeeded, dwCount;
- BOOL bRet = FALSE;
-
- hSCManager = OpenSCManagerW(NULL,
- NULL,
- SC_MANAGER_ALL_ACCESS);
- if (hSCManager)
- {
- hService = OpenServiceW(hSCManager,
- pInfo->pCurrentService->lpServiceName,
- SERVICE_ENUMERATE_DEPENDENTS);
- if (hService)
- {
- if (!EnumDependentServices(hService,
- SERVICE_ACTIVE,
- NULL,
- 0,
- &dwBytesNeeded,
- &dwCount))
- {
- if (GetLastError() == ERROR_MORE_DATA)
- bRet = TRUE;
- }
-
- CloseServiceHandle(hService);
- }
-
- CloseServiceHandle(hSCManager);
- }
-
- return bRet;
-}
-
-static BOOL
-DoInitDependsDialog(PMAIN_WND_INFO pInfo,
- HWND hDlg)
-{
+ LPENUM_SERVICE_STATUS lpDependencies;
+ DWORD dwCount;
LPTSTR lpPartialStr, lpStr;
DWORD fullLen;
HICON hIcon = NULL;
BOOL bRet = FALSE;
- if (pInfo)
+ if (pStopInfo)
{
SetWindowLongPtr(hDlg,
GWLP_USERDATA,
- (LONG_PTR)pInfo);
+ (LONG_PTR)pStopInfo);
hIcon = (HICON)LoadImage(hInstance,
MAKEINTRESOURCE(IDI_SM_ICON),
@@ -232,18 +227,19 @@
DestroyIcon(hIcon);
}
+ /* Add the label */
if (AllocAndLoadString(&lpPartialStr,
hInstance,
IDS_STOP_DEPENDS))
{
- fullLen = _tcslen(lpPartialStr) +
_tcslen(pInfo->pCurrentService->lpDisplayName) + 1;
+ fullLen = _tcslen(lpPartialStr) +
_tcslen(pStopInfo->pInfo->pCurrentService->lpDisplayName) + 1;
lpStr = HeapAlloc(ProcessHeap,
0,
fullLen * sizeof(TCHAR));
if (lpStr)
{
- _sntprintf(lpStr, fullLen, lpPartialStr,
pInfo->pCurrentService->lpDisplayName);
+ _sntprintf(lpStr, fullLen, lpPartialStr,
pStopInfo->pInfo->pCurrentService->lpDisplayName);
SendDlgItemMessage(hDlg,
IDC_STOP_DEPENDS,
@@ -262,6 +258,26 @@
0,
lpPartialStr);
}
+
+ /* Get the list of dependencies */
+ lpDependencies = GetDependentServices(pStopInfo->hMainService, &dwCount);
+ if (lpDependencies)
+ {
+ LPENUM_SERVICE_STATUS lpEnumServiceStatus;
+ DWORD i;
+
+ for (i = 0; i < dwCount; i++)
+ {
+ lpEnumServiceStatus = &lpDependencies[i];
+
+ /* Add the service to the listbox */
+ SendDlgItemMessage(hDlg,
+ IDC_STOP_DEPENDS_LB,
+ LB_ADDSTRING,
+ 0,
+ (LPARAM)lpEnumServiceStatus->lpDisplayName);
+ }
+ }
}
return bRet;
@@ -270,17 +286,16 @@
INT_PTR CALLBACK
StopDependsDialogProc(HWND hDlg,
- UINT message,
- WPARAM wParam,
- LPARAM lParam)
-{
- PMAIN_WND_INFO pInfo = NULL;
-
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ PSTOP_INFO pStopInfo = NULL;
/* Get the window context */
- pInfo = (PMAIN_WND_INFO)GetWindowLongPtr(hDlg,
+ pStopInfo = (PSTOP_INFO)GetWindowLongPtr(hDlg,
GWLP_USERDATA);
- if (pInfo == NULL && message != WM_INITDIALOG)
+ if (pStopInfo == NULL && message != WM_INITDIALOG)
{
return FALSE;
}
@@ -291,10 +306,10 @@
{
BOOL bRet = FALSE;
- pInfo = (PMAIN_WND_INFO)lParam;
- if (pInfo != NULL)
- {
- bRet = DoInitDependsDialog(pInfo, hDlg);
+ pStopInfo = (PSTOP_INFO)lParam;
+ if (pStopInfo != NULL)
+ {
+ bRet = DoInitDependsDialog(pStopInfo, hDlg);
}
return bRet;
@@ -322,47 +337,55 @@
BOOL
DoStop(PMAIN_WND_INFO pInfo)
{
- SC_HANDLE hSCManager = NULL;
+ STOP_INFO stopInfo;
+ SC_HANDLE hSCManager;
SC_HANDLE hService;
BOOL bHasDepends;
BOOL bRet = FALSE;
- bHasDepends = HasDependentServices(pInfo);
- if (bHasDepends)
- {
- INT ret = DialogBoxParam(hInstance,
- MAKEINTRESOURCE(IDD_DLG_DEPEND_STOP),
- pInfo->hMainWnd,
- StopDependsDialogProc,
- (LPARAM)pInfo);
- if (ret != IDOK)
- return FALSE;
- }
-
- 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)
- {
- if (bHasDepends)
- {
- StopDependentServices(pInfo,
- hSCManager,
- hService);
- }
-
- bRet = StopService(pInfo, hService);
-
- CloseServiceHandle(hService);
- }
-
- CloseServiceHandle(hSCManager);
- }
-
- return bRet;
-}
+ if (pInfo)
+ {
+ stopInfo.pInfo = pInfo;
+
+ 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;
+
+ if (HasDependentServices(hService))
+ {
+ INT ret = DialogBoxParam(hInstance,
+ MAKEINTRESOURCE(IDD_DLG_DEPEND_STOP),
+ pInfo->hMainWnd,
+ StopDependsDialogProc,
+ (LPARAM)&stopInfo);
+ if (ret == IDOK)
+ {
+ if (StopDependentServices(&stopInfo, hService))
+ {
+ bRet = StopService(&stopInfo, hService);
+ }
+ }
+ }
+ else
+ {
+ bRet = StopService(&stopInfo, hService);
+ }
+
+ CloseServiceHandle(hService);
+ }
+
+ CloseServiceHandle(hSCManager);
+ }
+ }
+
+ return bRet;
+}