mirror of
https://github.com/reactos/reactos.git
synced 2025-02-23 00:45:24 +00:00
[SYSSETUP] SetupStartService: Wait until the service is running
This commit is contained in:
parent
5ebcc6cdc1
commit
8f911f21b8
1 changed files with 24 additions and 2 deletions
|
@ -1508,7 +1508,9 @@ SetupStartService(
|
||||||
{
|
{
|
||||||
SC_HANDLE hManager = NULL;
|
SC_HANDLE hManager = NULL;
|
||||||
SC_HANDLE hService = NULL;
|
SC_HANDLE hService = NULL;
|
||||||
|
SERVICE_STATUS ServiceStatus;
|
||||||
DWORD dwError = ERROR_SUCCESS;
|
DWORD dwError = ERROR_SUCCESS;
|
||||||
|
DWORD dwRetries = 0;
|
||||||
|
|
||||||
hManager = OpenSCManagerW(NULL,
|
hManager = OpenSCManagerW(NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -1521,7 +1523,7 @@ SetupStartService(
|
||||||
|
|
||||||
hService = OpenServiceW(hManager,
|
hService = OpenServiceW(hManager,
|
||||||
lpServiceName,
|
lpServiceName,
|
||||||
SERVICE_START);
|
SERVICE_START | (bWait) ? SERVICE_QUERY_STATUS : 0);
|
||||||
if (hService == NULL)
|
if (hService == NULL)
|
||||||
{
|
{
|
||||||
dwError = GetLastError();
|
dwError = GetLastError();
|
||||||
|
@ -1531,7 +1533,27 @@ SetupStartService(
|
||||||
if (!StartService(hService, 0, NULL))
|
if (!StartService(hService, 0, NULL))
|
||||||
{
|
{
|
||||||
dwError = GetLastError();
|
dwError = GetLastError();
|
||||||
goto done;
|
if (dwError != ERROR_SERVICE_ALREADY_RUNNING)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
if (bWait)
|
||||||
|
{
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
if (!QueryServiceStatus(hService, &ServiceStatus))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (ServiceStatus.dwCurrentState != SERVICE_START_PENDING)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (dwRetries == 30)
|
||||||
|
break;
|
||||||
|
|
||||||
|
dwRetries++;
|
||||||
|
|
||||||
|
Sleep(5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
|
Loading…
Reference in a new issue