[SETUPAPI] GetDeviceInstanceKeyPath: Trying to open the hardware key opens the softwa...
[reactos.git] / dll / win32 / setupapi / cfgmgr.c
index 2c56fd1..98b0913 100644 (file)
@@ -236,19 +236,39 @@ GetDeviceInstanceKeyPath(
     {
         /* Software Key Path */
 
-        if (ulFlags & CM_REGISTRY_CONFIG)
+        ulTransferLength = 300 * sizeof(WCHAR);
+        ulLength = 300 * sizeof(WCHAR);
+        ret = PNP_GetDeviceRegProp(BindingHandle,
+                                   pszDeviceInst,
+                                   CM_DRP_DRIVER,
+                                   &ulType,
+                                   (PVOID)pszBuffer,
+                                   &ulTransferLength,
+                                   &ulLength,
+                                   0);
+        if (ret != CR_SUCCESS)
         {
-            SplitDeviceInstanceId(pszDeviceInst,
-                                  pszBuffer,
-                                  pszInstancePath);
+            ERR("PNP_GetDeviceRegProp() failed (Error %lu)\n", ret);
+            goto done;
+        }
+
+        TRACE("szBuffer: %S\n", pszBuffer);
+
+        SplitDeviceInstanceId(pszBuffer,
+                              pszBuffer,
+                              pszInstancePath);
 
+        TRACE("szBuffer: %S\n", pszBuffer);
+
+        if (ulFlags & CM_REGISTRY_CONFIG)
+        {
             if (ulHardwareProfile == 0)
             {
                 wsprintfW(pszKeyPath,
                           L"%s\\%s\\%s\\%s",
                           L"System\\CurrentControlSet\\Hardware Profiles",
                           L"Current",
-                          L"System\\CurrentControlSet\\Enum",
+                          L"System\\CurrentControlSet\\Control\\Class",
                           pszBuffer);
             }
             else
@@ -257,29 +277,15 @@ GetDeviceInstanceKeyPath(
                           L"%s\\%04lu\\%s\\%s",
                           L"System\\CurrentControlSet\\Hardware Profiles",
                           ulHardwareProfile,
-                          L"System\\CurrentControlSet\\Enum",
+                          L"System\\CurrentControlSet\\Control\\Class",
                           pszBuffer);
             }
         }
-        else if (ulFlags & CM_REGISTRY_USER)
-        {
-            wsprintfW(pszKeyPath,
-                      L"%s\\%s",
-                      L"System\\CurrentControlSet\\Enum",
-                      pszDeviceInst);
-
-            wcscpy(pszInstancePath,
-                   L"Device Parameters");
-        }
         else
         {
-            SplitDeviceInstanceId(pszDeviceInst,
-                                  pszBuffer,
-                                  pszInstancePath);
-
             wsprintfW(pszKeyPath,
                       L"%s\\%s",
-                      L"System\\CurrentControlSet\\Enum",
+                      L"System\\CurrentControlSet\\Control\\Class",
                       pszBuffer);
         }
     }
@@ -287,39 +293,19 @@ GetDeviceInstanceKeyPath(
     {
         /* Hardware Key Path */
 
-        ulTransferLength = 300 * sizeof(WCHAR);
-        ulLength = 300 * sizeof(WCHAR);
-        ret = PNP_GetDeviceRegProp(BindingHandle,
-                                   pszDeviceInst,
-                                   CM_DRP_DRIVER,
-                                   &ulType,
-                                   (PVOID)pszBuffer,
-                                   &ulTransferLength,
-                                   &ulLength,
-                                   0);
-        if (ret != CR_SUCCESS)
-        {
-            ERR("PNP_GetDeviceRegProp() failed (Error %lu)\n", ret);
-            goto done;
-        }
-
-        TRACE("szBuffer: %S\n", pszBuffer);
-
-        SplitDeviceInstanceId(pszBuffer,
-                              pszBuffer,
-                              pszInstancePath);
-
-        TRACE("szBuffer: %S\n", pszBuffer);
-
         if (ulFlags & CM_REGISTRY_CONFIG)
         {
+            SplitDeviceInstanceId(pszDeviceInst,
+                                  pszBuffer,
+                                  pszInstancePath);
+
             if (ulHardwareProfile == 0)
             {
                 wsprintfW(pszKeyPath,
                           L"%s\\%s\\%s\\%s",
                           L"System\\CurrentControlSet\\Hardware Profiles",
                           L"Current",
-                          L"System\\CurrentControlSet\\Control\\Class",
+                          L"System\\CurrentControlSet\\Enum",
                           pszBuffer);
             }
             else
@@ -328,15 +314,29 @@ GetDeviceInstanceKeyPath(
                           L"%s\\%04lu\\%s\\%s",
                           L"System\\CurrentControlSet\\Hardware Profiles",
                           ulHardwareProfile,
-                          L"System\\CurrentControlSet\\Control\\Class",
+                          L"System\\CurrentControlSet\\Enum",
                           pszBuffer);
             }
         }
+        else if (ulFlags & CM_REGISTRY_USER)
+        {
+            wsprintfW(pszKeyPath,
+                      L"%s\\%s",
+                      L"System\\CurrentControlSet\\Enum",
+                      pszDeviceInst);
+
+            wcscpy(pszInstancePath,
+                   L"Device Parameters");
+        }
         else
         {
+            SplitDeviceInstanceId(pszDeviceInst,
+                                  pszBuffer,
+                                  pszInstancePath);
+
             wsprintfW(pszKeyPath,
                       L"%s\\%s",
-                      L"System\\CurrentControlSet\\Control\\Class",
+                      L"System\\CurrentControlSet\\Enum",
                       pszBuffer);
         }
     }