Exemplo n.º 1
0
BOOL
DoStart(PMAIN_WND_INFO Info, LPWSTR lpStartParams)
{
    HWND hProgress;
    BOOL bRet = FALSE;

    /* Create a progress window to track the progress of the stopping service */
    hProgress = CreateProgressDialog(Info->hMainWnd,
                                     IDS_PROGRESS_INFO_START);
    if (hProgress)
    {
        /* Set the service name and reset the progress bag */
        InitializeProgressDialog(hProgress, Info->pCurrentService->lpServiceName);

        /* Start the requested service */
        bRet = DoStartService(Info, hProgress, lpStartParams);

        /* Complete and destroy the progress bar */
        DestroyProgressDialog(hProgress, bRet);
    }

    return bRet;
}
Exemplo n.º 2
0
BOOL
DoResume(PMAIN_WND_INFO Info)
{
    HWND hProgress;
    BOOL bRet = FALSE;

    /* Create a progress window to track the progress of the resuming service */
    hProgress = CreateProgressDialog(Info->hMainWnd,
                                     IDS_PROGRESS_INFO_RESUME);
    if (hProgress)
    {
        /* Set the service name and reset the progress bag */
        InitializeProgressDialog(hProgress, Info->pCurrentService->lpServiceName);

        /* Resume the requested service */
        bRet = DoControl(Info, hProgress, SERVICE_CONTROL_CONTINUE);

        /* Complete and destroy the progress bar */
        DestroyProgressDialog(hProgress, bRet);
    }

    return bRet;
}
Exemplo n.º 3
0
static BOOL
StopService(PMAIN_WND_INFO pInfo,
            LPWSTR lpServiceName,
            HWND hProgress OPTIONAL)
{
    SC_HANDLE hSCManager;
    SC_HANDLE hService;
    SERVICE_STATUS_PROCESS ServiceStatus;
    DWORD dwBytesNeeded;
    DWORD dwStartTime;
    DWORD dwTimeout;
    BOOL bRet = FALSE;

    if (hProgress)
    {
        /* Set the service name and reset the progress bag */
        InitializeProgressDialog(hProgress, lpServiceName);
    }

    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)
                {
                    /* Don't sleep for more than 3 seconds */
                    if (ServiceStatus.dwWaitHint > 3000)
                        ServiceStatus.dwWaitHint = 3000;

                    Sleep(ServiceStatus.dwWaitHint);

                    if (hProgress)
                    {
                        /* Increment the progress bar */
                        IncrementProgressBar(hProgress, DEFAULT_STEP);
                    }

                    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;
}