2006-11-08 11:47:44 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Services
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2007-08-24 18:27:12 +00:00
|
|
|
* FILE: base/applications/mscutils/servman/start.c
|
2006-11-08 11:47:44 +00:00
|
|
|
* PURPOSE: Start a service
|
2007-08-24 18:27:12 +00:00
|
|
|
* COPYRIGHT: Copyright 2005-2007 Ged Murphy <gedmurphy@reactos.org>
|
2006-11-08 11:47:44 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
static BOOL
|
2007-08-24 18:27:12 +00:00
|
|
|
DoStartService(PMAIN_WND_INFO Info,
|
|
|
|
HWND hProgDlg)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
|
|
|
SC_HANDLE hSCManager;
|
|
|
|
SC_HANDLE hSc;
|
|
|
|
SERVICE_STATUS_PROCESS ServiceStatus;
|
|
|
|
DWORD BytesNeeded = 0;
|
2007-08-28 19:54:25 +00:00
|
|
|
BOOL bRet = FALSE;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
hSCManager = OpenSCManager(NULL,
|
|
|
|
NULL,
|
|
|
|
SC_MANAGER_ALL_ACCESS);
|
2007-08-29 15:46:52 +00:00
|
|
|
if (hSCManager != NULL)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2007-08-28 19:54:25 +00:00
|
|
|
hSc = OpenService(hSCManager,
|
|
|
|
Info->pCurrentService->lpServiceName,
|
|
|
|
SERVICE_ALL_ACCESS);
|
|
|
|
if (hSc != NULL)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2007-08-28 19:54:25 +00:00
|
|
|
if (StartService(hSc,
|
2007-08-29 19:36:58 +00:00
|
|
|
0,
|
2007-08-28 19:54:25 +00:00
|
|
|
NULL))
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2007-08-28 19:54:25 +00:00
|
|
|
if (QueryServiceStatusEx(hSc,
|
|
|
|
SC_STATUS_PROCESS_INFO,
|
|
|
|
(LPBYTE)&ServiceStatus,
|
|
|
|
sizeof(SERVICE_STATUS_PROCESS),
|
|
|
|
&BytesNeeded))
|
|
|
|
{
|
2007-08-29 19:36:58 +00:00
|
|
|
DWORD dwStartTickCount = GetTickCount();
|
|
|
|
DWORD dwOldCheckPoint = ServiceStatus.dwCheckPoint;
|
2007-08-28 19:54:25 +00:00
|
|
|
|
|
|
|
while (ServiceStatus.dwCurrentState != SERVICE_RUNNING)
|
|
|
|
{
|
2007-08-29 19:36:58 +00:00
|
|
|
DWORD dwWaitTime = ServiceStatus.dwWaitHint / 10;
|
2007-08-28 19:54:25 +00:00
|
|
|
|
|
|
|
if(dwWaitTime < 1000)
|
|
|
|
dwWaitTime = 500;
|
|
|
|
else if (dwWaitTime > 10000)
|
|
|
|
dwWaitTime = 10000;
|
|
|
|
|
|
|
|
IncrementProgressBar(hProgDlg);
|
|
|
|
Sleep(dwWaitTime );
|
|
|
|
IncrementProgressBar(hProgDlg);
|
|
|
|
|
|
|
|
if (!QueryServiceStatusEx(hSc,
|
|
|
|
SC_STATUS_PROCESS_INFO,
|
|
|
|
(LPBYTE)&ServiceStatus,
|
|
|
|
sizeof(SERVICE_STATUS_PROCESS),
|
|
|
|
&BytesNeeded))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ServiceStatus.dwCheckPoint > dwOldCheckPoint)
|
|
|
|
{
|
|
|
|
/* The service is making progress, increment the progress bar */
|
|
|
|
IncrementProgressBar(hProgDlg);
|
|
|
|
dwStartTickCount = GetTickCount();
|
|
|
|
dwOldCheckPoint = ServiceStatus.dwCheckPoint;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(GetTickCount() - dwStartTickCount > ServiceStatus.dwWaitHint)
|
|
|
|
{
|
|
|
|
/* No progress made within the wait hint */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
2007-08-28 19:54:25 +00:00
|
|
|
|
|
|
|
CloseServiceHandle(hSc);
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
|
2007-08-28 19:54:25 +00:00
|
|
|
CloseServiceHandle(hSCManager);
|
|
|
|
}
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
if (ServiceStatus.dwCurrentState == SERVICE_RUNNING)
|
|
|
|
{
|
2007-08-24 18:27:12 +00:00
|
|
|
CompleteProgressBar(hProgDlg);
|
2006-11-08 11:47:44 +00:00
|
|
|
Sleep(1000);
|
2007-08-28 19:54:25 +00:00
|
|
|
bRet = TRUE;
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
else
|
2007-08-28 19:54:25 +00:00
|
|
|
GetError();
|
|
|
|
|
|
|
|
return bRet;
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
DoStart(PMAIN_WND_INFO Info)
|
|
|
|
{
|
|
|
|
HWND hProgDlg;
|
2007-08-24 18:27:12 +00:00
|
|
|
BOOL bRet = FALSE;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
2007-08-24 18:27:12 +00:00
|
|
|
hProgDlg = CreateProgressDialog(Info->hMainWnd,
|
2007-08-27 19:31:09 +00:00
|
|
|
Info->pCurrentService->lpServiceName,
|
2007-08-25 14:51:36 +00:00
|
|
|
IDS_PROGRESS_INFO_START);
|
2007-08-24 18:27:12 +00:00
|
|
|
|
|
|
|
if (hProgDlg)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2007-08-24 18:27:12 +00:00
|
|
|
bRet = DoStartService(Info,
|
|
|
|
hProgDlg);
|
2006-11-08 11:47:44 +00:00
|
|
|
|
2007-08-24 18:27:12 +00:00
|
|
|
SendMessage(hProgDlg,
|
|
|
|
WM_DESTROY,
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
}
|
2006-11-08 11:47:44 +00:00
|
|
|
|
2007-08-24 18:27:12 +00:00
|
|
|
return bRet;
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|