[SYSSETUP] Manually start PlugPlay service, and wait for it before continuing

That way, class installers are already registered before installing devices.

CORE-17538
This commit is contained in:
Hervé Poussineau 2021-04-07 19:26:06 +02:00
parent 52f4d8019b
commit 4d25869e0e
2 changed files with 33 additions and 2 deletions

View file

@ -1995,7 +1995,7 @@ HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","ErrorControl",0x00010001,0x00
HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","Group",0x00000000,"PlugPlay"
HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","ImagePath",0x00020000,"%SystemRoot%\system32\svchost.exe -k DcomLaunch"
HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","ObjectName",0x00000000,"LocalSystem"
HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","Start",0x00010001,0x00000002
HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","Start",0x00010001,0x00000003
HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay","Type",0x00010001,0x00000020
HKLM,"SYSTEM\CurrentControlSet\Services\PlugPlay\Parameters","ServiceDll",0x00020000,"%SystemRoot%\system32\umpnpmgr.dll"

View file

@ -486,7 +486,9 @@ EnableUserModePnpManager(VOID)
{
SC_HANDLE hSCManager = NULL;
SC_HANDLE hService = NULL;
SERVICE_STATUS_PROCESS ServiceStatus;
BOOL bRet = FALSE;
DWORD BytesNeeded, WaitTime;
hSCManager = OpenSCManagerW(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);
if (hSCManager == NULL)
@ -498,7 +500,7 @@ EnableUserModePnpManager(VOID)
hService = OpenServiceW(hSCManager,
L"PlugPlay",
SERVICE_CHANGE_CONFIG | SERVICE_START);
SERVICE_CHANGE_CONFIG | SERVICE_START | SERVICE_QUERY_STATUS);
if (hService == NULL)
{
DPRINT1("Unable to open PlugPlay service\n");
@ -524,6 +526,35 @@ EnableUserModePnpManager(VOID)
goto cleanup;
}
while (TRUE)
{
bRet = QueryServiceStatusEx(hService,
SC_STATUS_PROCESS_INFO,
(LPBYTE)&ServiceStatus,
sizeof(ServiceStatus),
&BytesNeeded);
if (!bRet)
{
DPRINT1("QueryServiceStatusEx() failed for PlugPlay service (error 0x%x)\n", GetLastError());
goto cleanup;
}
if (ServiceStatus.dwCurrentState != SERVICE_START_PENDING)
break;
WaitTime = ServiceStatus.dwWaitHint / 10;
if (WaitTime < 1000) WaitTime = 1000;
else if (WaitTime > 10000) WaitTime = 10000;
Sleep(WaitTime);
};
if (ServiceStatus.dwCurrentState != SERVICE_RUNNING)
{
bRet = FALSE;
DPRINT1("Failed to start PlugPlay service\n");
goto cleanup;
}
bRet = TRUE;
cleanup: