mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 18:15:11 +00:00
[SERVMAN] UI update and Error Management (#2653)
Purpose ======= - Current design does not warn user nor logs DEBUG traces when Service Start/Stop command fails or reach timeout. - Current Service Start/Stop progress window are WS_EX_TOOLWINDOW which reduce lisibility, is a ReactOS specificity without good reason. Proposed changes ================ - DPRINT1 traces added on failure cases. - Error Message box presented to user upon failure with explicit root cause identification. - Change Dialog definition to standard window.
This commit is contained in:
parent
140ec9d037
commit
b3947d5283
29 changed files with 138 additions and 67 deletions
|
@ -9,9 +9,12 @@
|
|||
|
||||
#include "precomp.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
#define MAX_WAIT_TIME 30000
|
||||
|
||||
BOOL
|
||||
DWORD
|
||||
DoControlService(LPWSTR ServiceName,
|
||||
HWND hProgress,
|
||||
DWORD Control)
|
||||
|
@ -27,6 +30,7 @@ DoControlService(LPWSTR ServiceName,
|
|||
DWORD MaxWait;
|
||||
DWORD ReqState, i;
|
||||
BOOL Result;
|
||||
DWORD dwResult = ERROR_SUCCESS;
|
||||
|
||||
/* Set the state we're interested in */
|
||||
switch (Control)
|
||||
|
@ -39,21 +43,23 @@ DoControlService(LPWSTR ServiceName,
|
|||
break;
|
||||
default:
|
||||
/* Unhandled control code */
|
||||
return FALSE;
|
||||
DPRINT1("Unknown control command: 0x%X\n", Control);
|
||||
return ERROR_INVALID_SERVICE_CONTROL;
|
||||
}
|
||||
|
||||
hSCManager = OpenSCManagerW(NULL,
|
||||
NULL,
|
||||
SC_MANAGER_CONNECT);
|
||||
if (!hSCManager) return FALSE;
|
||||
if (!hSCManager) return GetLastError();
|
||||
|
||||
hService = OpenServiceW(hSCManager,
|
||||
ServiceName,
|
||||
SERVICE_PAUSE_CONTINUE | SERVICE_INTERROGATE | SERVICE_QUERY_STATUS);
|
||||
if (!hService)
|
||||
{
|
||||
dwResult = GetLastError();
|
||||
CloseServiceHandle(hSCManager);
|
||||
return FALSE;
|
||||
return dwResult;
|
||||
}
|
||||
|
||||
/* Send the control message to the service */
|
||||
|
@ -109,6 +115,8 @@ DoControlService(LPWSTR ServiceName,
|
|||
&BytesNeeded))
|
||||
{
|
||||
/* Something went wrong... */
|
||||
dwResult = GetLastError();
|
||||
DPRINT1("QueryServiceStatusEx failed: %d\n", dwResult);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -123,23 +131,33 @@ DoControlService(LPWSTR ServiceName,
|
|||
else
|
||||
{
|
||||
/* It's not, make sure we haven't exceeded our wait time */
|
||||
if(GetTickCount() >= StartTickCount + MaxWait)
|
||||
if (GetTickCount() >= StartTickCount + MaxWait)
|
||||
{
|
||||
/* We have, give up */
|
||||
DPRINT1("Timeout\n");
|
||||
dwResult = ERROR_SERVICE_REQUEST_TIMEOUT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dwResult = GetLastError();
|
||||
}
|
||||
|
||||
if (ServiceStatus.dwCurrentState == ReqState)
|
||||
{
|
||||
Result = TRUE;
|
||||
dwResult = ERROR_SUCCESS;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dwResult = GetLastError();
|
||||
}
|
||||
|
||||
CloseServiceHandle(hService);
|
||||
CloseServiceHandle(hSCManager);
|
||||
|
||||
return Result;
|
||||
return dwResult;
|
||||
}
|
||||
|
|
|
@ -232,7 +232,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Управление на услугите"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -232,7 +232,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Ovldání služeb"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -232,7 +232,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Dienststeuerung"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -232,7 +232,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Service Control"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -232,7 +232,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Service Control"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -235,7 +235,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Control de servicios"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -232,7 +232,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Contrôle du Service"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -232,7 +232,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "בקרת שירות"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -232,7 +232,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Kontrol Layanan"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -232,7 +232,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Controllo dei servizi"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -232,7 +232,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "サービス コントロール"
|
||||
FONT 9, "MS UI Gothic", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -234,7 +234,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "서비스 컨트롤"
|
||||
FONT 9, "굴림", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -232,7 +232,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Tjeneste kontroll"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -242,7 +242,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Usługa kontrolna"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -237,7 +237,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Control servicii"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -232,7 +232,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Управление службами"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -237,7 +237,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Service Control"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -237,7 +237,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Kontrolli i shërbimeve"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -239,7 +239,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Tjänst kontroll"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -240,7 +240,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "ตัวควบคุมบริการ"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -234,7 +234,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Hizmet Denetimi"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -240,7 +240,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "Управління службами"
|
||||
FONT 8, "MS Shell Dlg", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -234,7 +234,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "服务控制"
|
||||
FONT 9, "宋体", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -234,7 +234,6 @@ IDD_DLG_PROGRESS DIALOGEX 6, 6, 255, 89
|
|||
CAPTION "服務控制"
|
||||
FONT 9, "新細明體", 0, 0
|
||||
STYLE DS_SHELLFONT | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE | DS_MODALFRAME
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
BEGIN
|
||||
CONTROL "", IDC_SERVCON_PROGRESS, "msctls_progress32", 0x50000000, 8, 46, 238, 13
|
||||
LTEXT "", IDC_SERVCON_INFO, 8, 5, 236, 11
|
||||
|
|
|
@ -7,9 +7,11 @@
|
|||
|
||||
#include <windef.h>
|
||||
#include <winbase.h>
|
||||
#include <winerror.h>
|
||||
#include <wingdi.h>
|
||||
#include <winsvc.h>
|
||||
#include <wincon.h>
|
||||
|
||||
#include <shlobj.h>
|
||||
#include <commdlg.h>
|
||||
#include <strsafe.h>
|
||||
|
@ -100,9 +102,9 @@ VOID ListViewSelectionChanged(PMAIN_WND_INFO Info, LPNMLISTVIEW pnmv);
|
|||
BOOL CreateListView(PMAIN_WND_INFO Info);
|
||||
|
||||
/* start / stop / control */
|
||||
BOOL DoStartService(LPWSTR ServiceName, HANDLE hProgress, LPWSTR lpStartParams);
|
||||
BOOL DoStopService(LPWSTR ServiceName, HANDLE hProgress);
|
||||
BOOL DoControlService(LPWSTR ServiceName, HWND hProgress, DWORD Control);
|
||||
DWORD DoStartService(LPWSTR ServiceName, HANDLE hProgress, LPWSTR lpStartParams);
|
||||
DWORD DoStopService(LPWSTR ServiceName, HANDLE hProgress);
|
||||
DWORD DoControlService(LPWSTR ServiceName, HWND hProgress, DWORD Control);
|
||||
|
||||
/* progress.c */
|
||||
#define DEFAULT_STEP 0
|
||||
|
@ -122,7 +124,6 @@ BOOL RefreshServiceList(PMAIN_WND_INFO Info);
|
|||
BOOL UpdateServiceStatus(ENUM_SERVICE_STATUS_PROCESS* pService);
|
||||
BOOL GetServiceList(PMAIN_WND_INFO Info);
|
||||
|
||||
|
||||
/* propsheet.c */
|
||||
typedef struct _SERVICEPROPSHEET
|
||||
{
|
||||
|
|
|
@ -26,6 +26,25 @@ typedef struct _PROGRESS_DATA
|
|||
|
||||
} PROGRESS_DATA, *PPROGRESS_DATA;
|
||||
|
||||
VOID ShowError(DWORD dwLastError)
|
||||
{
|
||||
LPWSTR lpMsg;
|
||||
|
||||
if (!FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
dwLastError,
|
||||
LANG_USER_DEFAULT,
|
||||
(LPWSTR)&lpMsg,
|
||||
0, NULL))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MessageBoxW(NULL, lpMsg, NULL, MB_OK | MB_ICONERROR);
|
||||
LocalFree(lpMsg);
|
||||
}
|
||||
|
||||
static VOID
|
||||
ResetProgressDialog(HWND hDlg,
|
||||
|
@ -67,6 +86,7 @@ ResetProgressDialog(HWND hDlg,
|
|||
unsigned int __stdcall ActionThread(void* Param)
|
||||
{
|
||||
PPROGRESS_DATA ProgressData = (PPROGRESS_DATA)Param;
|
||||
DWORD dwResult;
|
||||
|
||||
if (ProgressData->Action == ACTION_START)
|
||||
{
|
||||
|
@ -76,13 +96,18 @@ unsigned int __stdcall ActionThread(void* Param)
|
|||
IDS_PROGRESS_INFO_START);
|
||||
|
||||
/* Start the service */
|
||||
if (DoStartService(ProgressData->ServiceName,
|
||||
ProgressData->hProgress,
|
||||
ProgressData->Param))
|
||||
dwResult = DoStartService(ProgressData->ServiceName,
|
||||
ProgressData->hProgress,
|
||||
ProgressData->Param);
|
||||
if (dwResult == ERROR_SUCCESS)
|
||||
{
|
||||
/* We're done, slide the progress bar up to the top */
|
||||
CompleteProgressBar(ProgressData->hProgress);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowError(dwResult);
|
||||
}
|
||||
}
|
||||
else if (ProgressData->Action == ACTION_STOP || ProgressData->Action == ACTION_RESTART)
|
||||
{
|
||||
|
@ -108,11 +133,16 @@ unsigned int __stdcall ActionThread(void* Param)
|
|||
IDS_PROGRESS_INFO_STOP);
|
||||
|
||||
/* Stop the requested service */
|
||||
if (DoStopService(ProgressData->ServiceName,
|
||||
ProgressData->hProgress))
|
||||
dwResult = DoStopService(ProgressData->ServiceName,
|
||||
ProgressData->hProgress);
|
||||
if (dwResult == ERROR_SUCCESS)
|
||||
{
|
||||
CompleteProgressBar(ProgressData->hProgress);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowError(dwResult);
|
||||
}
|
||||
|
||||
/* Move onto the next string */
|
||||
while (*lpStr != L'\0')
|
||||
|
@ -124,11 +154,16 @@ unsigned int __stdcall ActionThread(void* Param)
|
|||
ProgressData->ServiceName,
|
||||
IDS_PROGRESS_INFO_STOP);
|
||||
|
||||
if (DoStopService(ProgressData->ServiceName,
|
||||
ProgressData->hProgress))
|
||||
dwResult = DoStopService(ProgressData->ServiceName,
|
||||
ProgressData->hProgress);
|
||||
if (dwResult == ERROR_SUCCESS)
|
||||
{
|
||||
CompleteProgressBar(ProgressData->hProgress);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowError(dwResult);
|
||||
}
|
||||
|
||||
|
||||
/* If this was a restart, we'll need to start the service back up */
|
||||
|
@ -140,13 +175,18 @@ unsigned int __stdcall ActionThread(void* Param)
|
|||
IDS_PROGRESS_INFO_START);
|
||||
|
||||
/* Start the service */
|
||||
if (DoStartService(ProgressData->ServiceName,
|
||||
ProgressData->hProgress,
|
||||
NULL))
|
||||
dwResult = DoStartService(ProgressData->ServiceName,
|
||||
ProgressData->hProgress,
|
||||
NULL);
|
||||
if (dwResult == ERROR_SUCCESS)
|
||||
{
|
||||
/* We're done, slide the progress bar up to the top */
|
||||
CompleteProgressBar(ProgressData->hProgress);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowError(dwResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ProgressData->Action == ACTION_PAUSE)
|
||||
|
@ -157,13 +197,18 @@ unsigned int __stdcall ActionThread(void* Param)
|
|||
IDS_PROGRESS_INFO_PAUSE);
|
||||
|
||||
/* Pause the service */
|
||||
if (DoControlService(ProgressData->ServiceName,
|
||||
ProgressData->hProgress,
|
||||
SERVICE_CONTROL_PAUSE))
|
||||
dwResult = DoControlService(ProgressData->ServiceName,
|
||||
ProgressData->hProgress,
|
||||
SERVICE_CONTROL_PAUSE);
|
||||
if (dwResult == ERROR_SUCCESS)
|
||||
{
|
||||
/* We're done, slide the progress bar up to the top */
|
||||
CompleteProgressBar(ProgressData->hProgress);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowError(dwResult);
|
||||
}
|
||||
}
|
||||
else if (ProgressData->Action == ACTION_RESUME)
|
||||
{
|
||||
|
@ -173,13 +218,18 @@ unsigned int __stdcall ActionThread(void* Param)
|
|||
IDS_PROGRESS_INFO_RESUME);
|
||||
|
||||
/* resume the service */
|
||||
if (DoControlService(ProgressData->ServiceName,
|
||||
ProgressData->hProgress,
|
||||
SERVICE_CONTROL_CONTINUE))
|
||||
dwResult = DoControlService(ProgressData->ServiceName,
|
||||
ProgressData->hProgress,
|
||||
SERVICE_CONTROL_CONTINUE);
|
||||
if (dwResult == ERROR_SUCCESS)
|
||||
{
|
||||
/* We're done, slide the progress bar up to the top */
|
||||
CompleteProgressBar(ProgressData->hProgress);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowError(dwResult);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,9 +9,12 @@
|
|||
|
||||
#include "precomp.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
#define MAX_WAIT_TIME 30000
|
||||
|
||||
BOOL
|
||||
DWORD
|
||||
DoStartService(LPWSTR ServiceName,
|
||||
HANDLE hProgress,
|
||||
LPWSTR lpStartParams)
|
||||
|
@ -29,6 +32,7 @@ DoStartService(LPWSTR ServiceName,
|
|||
BOOL bWhiteSpace = TRUE;
|
||||
LPWSTR lpChar;
|
||||
DWORD dwArgsCount = 0;
|
||||
DWORD dwResult = ERROR_SUCCESS;
|
||||
LPCWSTR *lpArgsVector = NULL;
|
||||
|
||||
if (lpStartParams != NULL)
|
||||
|
@ -59,7 +63,7 @@ DoStartService(LPWSTR ServiceName,
|
|||
*/
|
||||
lpArgsVector = LocalAlloc(LMEM_FIXED, dwArgsCount * sizeof(LPCWSTR));
|
||||
if (!lpArgsVector)
|
||||
return FALSE;
|
||||
return GetLastError();
|
||||
|
||||
/* Fill the arguments vector */
|
||||
dwArgsCount = 0;
|
||||
|
@ -91,9 +95,10 @@ DoStartService(LPWSTR ServiceName,
|
|||
SC_MANAGER_CONNECT);
|
||||
if (!hSCManager)
|
||||
{
|
||||
dwResult = GetLastError();
|
||||
if (lpArgsVector)
|
||||
LocalFree((LPVOID)lpArgsVector);
|
||||
return FALSE;
|
||||
return dwResult;
|
||||
}
|
||||
|
||||
hService = OpenServiceW(hSCManager,
|
||||
|
@ -101,10 +106,11 @@ DoStartService(LPWSTR ServiceName,
|
|||
SERVICE_START | SERVICE_QUERY_STATUS);
|
||||
if (!hService)
|
||||
{
|
||||
dwResult = GetLastError();
|
||||
CloseServiceHandle(hSCManager);
|
||||
if (lpArgsVector)
|
||||
LocalFree((LPVOID)lpArgsVector);
|
||||
return FALSE;
|
||||
return dwResult;
|
||||
}
|
||||
|
||||
/* Start the service */
|
||||
|
@ -167,6 +173,8 @@ DoStartService(LPWSTR ServiceName,
|
|||
&BytesNeeded))
|
||||
{
|
||||
/* Something went wrong... */
|
||||
dwResult = GetLastError();
|
||||
DPRINT1("QueryServiceStatusEx failed: %d\n", dwResult);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -183,24 +191,29 @@ DoStartService(LPWSTR ServiceName,
|
|||
if (GetTickCount() >= StartTickCount + MaxWait)
|
||||
{
|
||||
/* We have, give up */
|
||||
DPRINT1("Timeout\n");
|
||||
dwResult = ERROR_SERVICE_REQUEST_TIMEOUT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dwResult = GetLastError();
|
||||
}
|
||||
|
||||
if (ServiceStatus.dwCurrentState == SERVICE_RUNNING)
|
||||
{
|
||||
Result = TRUE;
|
||||
dwResult = ERROR_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
CloseServiceHandle(hService);
|
||||
|
||||
CloseServiceHandle(hSCManager);
|
||||
|
||||
if (lpArgsVector)
|
||||
LocalFree((LPVOID)lpArgsVector);
|
||||
|
||||
return Result;
|
||||
return dwResult;
|
||||
}
|
||||
|
|
|
@ -9,9 +9,12 @@
|
|||
|
||||
#include "precomp.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
#define MAX_WAIT_TIME 30000
|
||||
|
||||
BOOL
|
||||
DWORD
|
||||
DoStopService(_In_z_ LPWSTR ServiceName,
|
||||
_In_opt_ HANDLE hProgress)
|
||||
{
|
||||
|
@ -22,21 +25,21 @@ DoStopService(_In_z_ LPWSTR ServiceName,
|
|||
DWORD StartTime;
|
||||
DWORD WaitTime;
|
||||
DWORD Timeout;
|
||||
BOOL bRet = FALSE;
|
||||
|
||||
|
||||
DWORD dwResult = ERROR_SUCCESS;
|
||||
|
||||
hSCManager = OpenSCManagerW(NULL,
|
||||
NULL,
|
||||
SC_MANAGER_CONNECT);
|
||||
if (!hSCManager) return FALSE;
|
||||
if (!hSCManager) return GetLastError();
|
||||
|
||||
hService = OpenServiceW(hSCManager,
|
||||
ServiceName,
|
||||
SERVICE_STOP | SERVICE_QUERY_STATUS);
|
||||
if (!hService)
|
||||
{
|
||||
dwResult = GetLastError();
|
||||
CloseServiceHandle(hSCManager);
|
||||
return FALSE;
|
||||
return dwResult;
|
||||
}
|
||||
|
||||
if (hProgress)
|
||||
|
@ -90,21 +93,31 @@ DoStopService(_In_z_ LPWSTR ServiceName,
|
|||
if (GetTickCount() - StartTime > Timeout)
|
||||
{
|
||||
/* Yep, give up */
|
||||
DPRINT1("Timeout\n");
|
||||
dwResult = ERROR_SERVICE_REQUEST_TIMEOUT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dwResult = GetLastError();
|
||||
DPRINT1("QueryServiceStatusEx failed: %d\n", dwResult);
|
||||
}
|
||||
}
|
||||
|
||||
/* If the service is stopped, return TRUE */
|
||||
if (ServiceStatus.dwCurrentState == SERVICE_STOPPED)
|
||||
{
|
||||
bRet = TRUE;
|
||||
dwResult = ERROR_SUCCESS;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dwResult = GetLastError();
|
||||
}
|
||||
|
||||
CloseServiceHandle(hService);
|
||||
|
||||
CloseServiceHandle(hSCManager);
|
||||
|
||||
return bRet;
|
||||
return dwResult;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue