Author: gedmurphy
Date: Tue Jan 5 19:08:41 2010
New Revision: 44951
URL:
http://svn.reactos.org/svn/reactos?rev=44951&view=rev
Log:
- Reimplement service stop routines.
- Stopping single services should now work again, full dependency trees won't yet.
Modified:
trunk/reactos/base/applications/mscutils/servman/control.c
trunk/reactos/base/applications/mscutils/servman/precomp.h
trunk/reactos/base/applications/mscutils/servman/progress.c
trunk/reactos/base/applications/mscutils/servman/start.c
trunk/reactos/base/applications/mscutils/servman/stop.c
Modified: trunk/reactos/base/applications/mscutils/servman/control.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/control.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mscutils/servman/control.c [iso-8859-1] Tue Jan 5
19:08:41 2010
@@ -48,7 +48,7 @@
DWORD dwOldCheckPoint = ServiceStatus.dwCheckPoint;
DWORD dwMaxWait = 2000 * 60; // wait for 2 mins
- IncrementProgressBar(hProgDlg);
+ IncrementProgressBar(hProgDlg, DEFAULT_STEP);
while (ServiceStatus.dwCurrentState != Control)
{
@@ -66,7 +66,7 @@
if (ServiceStatus.dwCheckPoint > dwOldCheckPoint)
{
/* The service is making progress, increment the progress bar
*/
- IncrementProgressBar(hProgDlg);
+ IncrementProgressBar(hProgDlg, DEFAULT_STEP);
dwStartTickCount = GetTickCount();
dwOldCheckPoint = ServiceStatus.dwCheckPoint;
}
Modified: trunk/reactos/base/applications/mscutils/servman/precomp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/precomp.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mscutils/servman/precomp.h [iso-8859-1] Tue Jan 5
19:08:41 2010
@@ -94,8 +94,10 @@
BOOL DoResume(PMAIN_WND_INFO Info);
/* progress.c */
-HWND CreateProgressDialog(HWND hParent, LPTSTR lpServiceName, UINT Event);
-VOID IncrementProgressBar(HWND hProgDlg);
+#define DEFAULT_STEP 0
+HWND CreateProgressDialog(HWND hParent, LPTSTR lpServiceName, UINT LabelId);
+BOOL DestroyProgressDialog(HWND hProgDlg, BOOL bComplete);
+VOID IncrementProgressBar(HWND hProgDlg, UINT NewPos);
VOID CompleteProgressBar(HWND hProgDlg);
/* query.c */
Modified: trunk/reactos/base/applications/mscutils/servman/progress.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/progress.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mscutils/servman/progress.c [iso-8859-1] Tue Jan 5
19:08:41 2010
@@ -18,41 +18,51 @@
hProgBar = GetDlgItem(hProgDlg,
IDC_SERVCON_PROGRESS);
-
if (hProgBar)
{
INT pos = 0;
- pos = SendMessage(hProgBar,
- PBM_GETPOS,
- 0,
- 0);
+ pos = SendMessageW(hProgBar,
+ PBM_GETPOS,
+ 0,
+ 0);
- for (; pos <= PROGRESSRANGE; pos++)
+ while (pos <= PROGRESSRANGE)
{
- SendMessage(hProgBar,
- PBM_DELTAPOS,
- pos,
- 0);
+ SendMessageW(hProgBar,
+ PBM_DELTAPOS,
+ pos,
+ 0);
Sleep(15);
+ pos++;
}
}
}
VOID
-IncrementProgressBar(HWND hProgDlg)
+IncrementProgressBar(HWND hProgDlg,
+ UINT NewPos)
{
HWND hProgBar;
hProgBar = GetDlgItem(hProgDlg,
IDC_SERVCON_PROGRESS);
-
if (hProgBar)
{
- SendMessage(hProgBar,
- PBM_STEPIT,
- 0,
- 0);
+ if (NewPos == DEFAULT_STEP)
+ {
+ SendMessageW(hProgBar,
+ PBM_STEPIT,
+ 0,
+ 0);
+ }
+ else
+ {
+ SendMessageW(hProgBar,
+ PBM_SETPOS,
+ NewPos,
+ 0);
+ }
}
}
@@ -68,18 +78,21 @@
{
HWND hProgBar;
- /* set the progress bar range and step */
+ /* Get a handle to the progress bar */
hProgBar = GetDlgItem(hDlg,
IDC_SERVCON_PROGRESS);
- SendMessage(hProgBar,
- PBM_SETRANGE,
- 0,
- MAKELPARAM(0, PROGRESSRANGE));
- SendMessage(hProgBar,
- PBM_SETSTEP,
- (WPARAM)1,
- 0);
+ /* Set the progress bar range */
+ SendMessageW(hProgBar,
+ PBM_SETRANGE,
+ 0,
+ MAKELPARAM(0, PROGRESSRANGE));
+
+ /* Set the progress bar step */
+ SendMessageW(hProgBar,
+ PBM_SETSTEP,
+ (WPARAM)1,
+ 0);
}
break;
@@ -98,43 +111,70 @@
}
return TRUE;
-
}
HWND
CreateProgressDialog(HWND hParent,
LPTSTR lpServiceName,
- UINT Event)
+ UINT LabelId)
{
HWND hProgDlg;
- TCHAR ProgDlgBuf[100];
+ LPWSTR lpProgStr;
/* open the progress dialog */
- hProgDlg = CreateDialog(hInstance,
- MAKEINTRESOURCE(IDD_DLG_PROGRESS),
- hParent,
- ProgressDialogProc);
+ hProgDlg = CreateDialogW(hInstance,
+ MAKEINTRESOURCEW(IDD_DLG_PROGRESS),
+ hParent,
+ ProgressDialogProc);
if (hProgDlg != NULL)
{
- /* write the info to the progress dialog */
- LoadString(hInstance,
- Event,
- ProgDlgBuf,
- sizeof(ProgDlgBuf) / sizeof(TCHAR));
+ /* Load the label Id */
+ if (AllocAndLoadString(&lpProgStr,
+ hInstance,
+ LabelId))
+ {
+ /* Write it to the dialog */
+ SendDlgItemMessageW(hProgDlg,
+ IDC_SERVCON_INFO,
+ WM_SETTEXT,
+ 0,
+ (LPARAM)lpProgStr);
- SendDlgItemMessage(hProgDlg,
- IDC_SERVCON_INFO,
- WM_SETTEXT,
- 0,
- (LPARAM)ProgDlgBuf);
+ HeapFree(GetProcessHeap(),
+ 0,
+ lpProgStr);
+ }
- /* write the service name to the progress dialog */
- SendDlgItemMessage(hProgDlg,
- IDC_SERVCON_NAME,
- WM_SETTEXT,
- 0,
- (LPARAM)lpServiceName);
+ /* Write the service name to the dialog */
+ SendDlgItemMessageW(hProgDlg,
+ IDC_SERVCON_NAME,
+ WM_SETTEXT,
+ 0,
+ (LPARAM)lpServiceName);
}
return hProgDlg;
}
+
+BOOL
+DestroyProgressDialog(HWND hwnd,
+ BOOL bComplete)
+{
+ BOOL bRet = FALSE;
+
+ if (hwnd)
+ {
+ if (bComplete)
+ {
+ /* Complete the progress bar */
+ CompleteProgressBar(hwnd);
+
+ /* Wait for asthetics */
+ Sleep(500);
+ }
+
+ bRet = DestroyWindow(hwnd);
+ }
+
+ return bRet;
+}
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] Tue Jan 5
19:08:41 2010
@@ -121,7 +121,7 @@
if (hProgDlg)
{
- IncrementProgressBar(hProgDlg);
+ IncrementProgressBar(hProgDlg, DEFAULT_STEP);
bRet = DoStartService(Info,
hProgDlg);
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] Tue Jan 5
19:08:41 2010
@@ -12,60 +12,97 @@
static BOOL
StopService(PMAIN_WND_INFO pInfo,
- LPWSTR lpServiceName)
+ LPWSTR lpServiceName,
+ HWND hProgress OPTIONAL)
{
- //SERVICE_STATUS_PROCESS ServiceStatus;
- //DWORD dwBytesNeeded;
- //DWORD dwStartTime;
- // DWORD dwTimeout;
- //HWND hProgDlg;
+ SC_HANDLE hSCManager;
+ SC_HANDLE hService;
+ SERVICE_STATUS_PROCESS ServiceStatus;
+ DWORD dwBytesNeeded;
+ DWORD dwStartTime;
+ DWORD dwTimeout;
BOOL bRet = FALSE;
-/*
- dwStartTime = GetTickCount();
- dwTimeout = 30000; // 30 secs
-
- hProgDlg = CreateProgressDialog(pStopInfo->pInfo->hMainWnd,
-
pStopInfo->pInfo->pCurrentService->lpServiceName,
- IDS_PROGRESS_INFO_STOP);
- if (hProgDlg)
- {
- IncrementProgressBar(hProgDlg);
-
- if (ControlService(hService,
- SERVICE_CONTROL_STOP,
- (LPSERVICE_STATUS)&ServiceStatus))
- {
- while (ServiceStatus.dwCurrentState != SERVICE_STOPPED)
- {
- Sleep(ServiceStatus.dwWaitHint);
-
- if (QueryServiceStatusEx(hService,
- SC_STATUS_PROCESS_INFO,
- (LPBYTE)&ServiceStatus,
- sizeof(SERVICE_STATUS_PROCESS),
- &dwBytesNeeded))
- {
- if (GetTickCount() - dwStartTime > dwTimeout)
+
+ if (hProgress)
+ {
+ /* Increment the progress bar */
+ IncrementProgressBar(hProgress, DEFAULT_STEP);
+ }
+
+ hSCManager = OpenSCManager(NULL,
+ NULL,
+ SC_MANAGER_CONNECT);
+ if (hSCManager)
+ {
+ hService = OpenService(hSCManager,
+ lpServiceName,
+ SERVICE_STOP | SERVICE_QUERY_STATUS);
+ if (hService)
+ {
+ if (hProgress)
+ {
+ /* Increment the progress bar */
+ IncrementProgressBar(hProgress, DEFAULT_STEP);
+ }
+
+ /* Set the wait time to 30 secs */
+ dwStartTime = GetTickCount();
+ dwTimeout = 30000;
+
+ /* Send the service the stop code */
+ if (ControlService(hService,
+ SERVICE_CONTROL_STOP,
+ (LPSERVICE_STATUS)&ServiceStatus))
+ {
+ if (hProgress)
+ {
+ /* Increment the progress bar */
+ IncrementProgressBar(hProgress, DEFAULT_STEP);
+ }
+
+ while (ServiceStatus.dwCurrentState != SERVICE_STOPPED)
+ {
+ Sleep(ServiceStatus.dwWaitHint);
+
+ if (hProgress)
{
- We exceeded our max wait time, give up
- break;
+ /* Increment the progress bar */
+ IncrementProgressBar(hProgress, DEFAULT_STEP);
}
- }
- }
-
- if (ServiceStatus.dwCurrentState == SERVICE_STOPPED)
- {
- bRet = TRUE;
- }
- }
-
- CompleteProgressBar(hProgDlg);
- Sleep(500);
- DestroyWindow(hProgDlg);
+
+ if (QueryServiceStatusEx(hService,
+ SC_STATUS_PROCESS_INFO,
+ (LPBYTE)&ServiceStatus,
+ sizeof(SERVICE_STATUS_PROCESS),
+ &dwBytesNeeded))
+ {
+ /* Have we exceeded our wait time? */
+ if (GetTickCount() - dwStartTime > dwTimeout)
+ {
+ /* Yep, give up */
+ break;
+ }
+ }
+ }
+
+ /* If the service is stopped, return TRUE */
+ if (ServiceStatus.dwCurrentState == SERVICE_STOPPED)
+ {
+ bRet = TRUE;
+ }
+ }
+
+ CloseServiceHandle(hService);
+ }
+
+ CloseServiceHandle(hSCManager);
}
-*/
+
return bRet;
}
+
+
+
static BOOL
StopDependantServices(PMAIN_WND_INFO pInfo,
@@ -118,6 +155,7 @@
BOOL
DoStop(PMAIN_WND_INFO pInfo)
{
+ HWND hProgress;
LPWSTR lpServiceList;
BOOL bRet = FALSE;
@@ -138,18 +176,24 @@
(LPARAM)lpServiceList) == IDOK)
{
/* Stop all the dependant services */
- if (StopDependantServices(pInfo,
pInfo->pCurrentService->lpServiceName))
- {
- /* Finally stop the requested service */
- bRet = StopService(pInfo,
pInfo->pCurrentService->lpServiceName);
- }
- }
- }
- }
- else
- {
- /* No dependants, just stop the service */
- bRet = StopService(pInfo, pInfo->pCurrentService->lpServiceName);
+ StopDependantServices(pInfo,
pInfo->pCurrentService->lpServiceName);
+ }
+ }
+ }
+
+ /* Create a progress window to track the progress of the stopping service */
+ hProgress = CreateProgressDialog(pInfo->hMainWnd,
+ pInfo->pCurrentService->lpServiceName,
+ IDS_PROGRESS_INFO_STOP);
+
+ /* Finally, stop the requested service */
+ bRet = StopService(pInfo,
+ pInfo->pCurrentService->lpServiceName,
+ hProgress);
+
+ if (hProgress)
+ {
+ DestroyProgressDialog(hProgress, TRUE);
}
}