[SYSSETUP] Manually start PlugPlay service, and wait for it before continuing
authorHervé Poussineau <hpoussin@reactos.org>
Wed, 7 Apr 2021 17:26:06 +0000 (19:26 +0200)
committerHervé Poussineau <hpoussin@reactos.org>
Wed, 7 Apr 2021 17:35:50 +0000 (19:35 +0200)
That way, class installers are already registered before installing devices.

CORE-17538

boot/bootdata/hivesys.inf
dll/win32/syssetup/install.c

index 7dc2c11..fc218fe 100644 (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"
 
index f0ce192..ba8fd22 100644 (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: