[PATCH v2] setupapi: Also start newly installed root PnP services in SetupDiInstallDevice().

Zebediah Figura z.figura12 at gmail.com
Wed Jun 26 22:32:26 CDT 2019


Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
 dlls/setupapi/devinst.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c
index b7625644bec..c38d518fb6f 100644
--- a/dlls/setupapi/devinst.c
+++ b/dlls/setupapi/devinst.c
@@ -31,6 +31,7 @@
 #include "wingdi.h"
 #include "winuser.h"
 #include "winnls.h"
+#include "winsvc.h"
 #include "setupapi.h"
 #include "wine/debug.h"
 #include "wine/heap.h"
@@ -4735,9 +4736,12 @@ BOOL WINAPI SetupDiInstallDevice(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data)
     static const WCHAR dothwW[] = {'.','H','W',0};
     static const WCHAR dotservicesW[] = {'.','S','e','r','v','i','c','e','s',0};
     static const WCHAR addserviceW[] = {'A','d','d','S','e','r','v','i','c','e',0};
+    static const WCHAR rootW[] = {'r','o','o','t','\\',0};
     WCHAR section[LINE_LEN], section_ext[LINE_LEN], subsection[LINE_LEN], inf_path[MAX_PATH], *extptr, *filepart;
+    WCHAR svc_name[LINE_LEN] = {0};
     UINT install_flags = SPINST_ALL;
     HKEY driver_key, device_key;
+    SC_HANDLE manager, service;
     struct device *device;
     struct driver *driver;
     void *callback_ctx;
@@ -4806,7 +4810,6 @@ BOOL WINAPI SetupDiInstallDevice(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data)
 
             if (SetupGetIntField(&ctx, 2, &flags) && (flags & SPSVCINST_ASSOCSERVICE))
             {
-                WCHAR svc_name[LINE_LEN];
                 if (SetupGetStringFieldW(&ctx, 1, svc_name, ARRAY_SIZE(svc_name), NULL) && svc_name[0])
                     RegSetValueExW(device->key, Service, 0, REG_SZ, (BYTE *)svc_name, strlenW(svc_name) * sizeof(WCHAR));
                 break;
@@ -4827,5 +4830,24 @@ BOOL WINAPI SetupDiInstallDevice(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data)
 
     RegCloseKey(device_key);
     RegCloseKey(driver_key);
+
+    if (!strncmpiW(device->instanceId, rootW, strlenW(rootW)) && svc_name[0]
+            && (manager = OpenSCManagerW(NULL, NULL, SC_MANAGER_CONNECT)))
+    {
+        if ((service = OpenServiceW(manager, svc_name, SERVICE_START)))
+        {
+            SERVICE_STATUS status;
+            if (!StartServiceW(service, 0, NULL) && GetLastError() != ERROR_SERVICE_ALREADY_RUNNING)
+            {
+                ERR("Failed to start service %s for device %s, error %u.\n",
+                        debugstr_w(svc_name), debugstr_w(device->instanceId), GetLastError());
+            }
+            CloseServiceHandle(service);
+        }
+        else
+            ERR("Failed to open service %s for device %s.\n", debugstr_w(svc_name), debugstr_w(device->instanceId));
+        CloseServiceHandle(manager);
+    }
+
     return TRUE;
 }
-- 
2.22.0




More information about the wine-devel mailing list