[NETCFGX] Set the ComponentId value when a NIC is installed.
[reactos.git] / dll / win32 / netcfgx / installer.c
index 995b85d..ccde401 100644 (file)
@@ -100,6 +100,7 @@ InstallNetDevice(
     LPCWSTR BusType)
 {
     LPWSTR InstanceId = NULL;
+    LPWSTR ComponentId = NULL;
     LPWSTR DeviceName = NULL;
     LPWSTR ExportName = NULL;
     LONG rc;
@@ -109,6 +110,15 @@ InstallNetDevice(
     HKEY hConnectionKey = NULL;
     DWORD dwShowIcon, dwLength, dwValue;
     WCHAR szBuffer[300];
+    PWSTR ptr;
+
+    /* Install the adapter */
+    if (!SetupDiInstallDevice(DeviceInfoSet, DeviceInfoData))
+    {
+        rc = GetLastError();
+        ERR("SetupDiInstallDevice() failed (Error %lu)\n", rc);
+        goto cleanup;
+    }
 
     /* Get Instance ID */
     if (SetupDiGetDeviceInstanceIdW(DeviceInfoSet, DeviceInfoData, NULL, 0, &dwLength))
@@ -133,6 +143,19 @@ InstallNetDevice(
         goto cleanup;
     }
 
+    ComponentId = HeapAlloc(GetProcessHeap(), 0, dwLength * sizeof(WCHAR));
+    if (!ComponentId)
+    {
+        ERR("HeapAlloc() failed\n");
+        rc = ERROR_NOT_ENOUGH_MEMORY;
+        goto cleanup;
+    }
+
+    wcscpy(ComponentId, InstanceId);
+    ptr = wcsrchr(ComponentId, L'\\');
+    if (ptr != NULL)
+        *ptr = UNICODE_NULL;
+
     /* Create device name */
     DeviceName = HeapAlloc(GetProcessHeap(), 0, (wcslen(L"\\Device\\") + wcslen(UuidString)) * sizeof(WCHAR) + sizeof(UNICODE_NULL));
     if (!DeviceName)
@@ -242,6 +265,13 @@ InstallNetDevice(
         goto cleanup;
     }
 
+    rc = RegSetValueExW(hKey, L"ComponentId", 0, REG_SZ, (const BYTE*)ComponentId, (wcslen(ComponentId) + 1) * sizeof(WCHAR));
+    if (rc != ERROR_SUCCESS)
+    {
+        ERR("RegSetValueExW() failed with error 0x%lx\n", rc);
+        goto cleanup;
+    }
+
     if (BusType)
     {
         rc = RegSetValueExW(hKey, L"BusType", 0, REG_SZ, (const BYTE*)BusType, (wcslen(BusType) + 1) * sizeof(WCHAR));
@@ -318,7 +348,7 @@ InstallNetDevice(
         goto cleanup;
     }
 
-    rc = RegSetValueExW(hConnectionKey, L"PnpInstanceId", 0, REG_SZ, (const BYTE*)InstanceId, (wcslen(InstanceId) + 1) * sizeof(WCHAR));
+    rc = RegSetValueExW(hConnectionKey, L"PnpInstanceID", 0, REG_SZ, (const BYTE*)InstanceId, (wcslen(InstanceId) + 1) * sizeof(WCHAR));
     if (rc != ERROR_SUCCESS)
     {
         ERR("RegSetValueExW() failed with error 0x%lx\n", rc);
@@ -363,6 +393,7 @@ InstallNetDevice(
 
 cleanup:
     HeapFree(GetProcessHeap(), 0, InstanceId);
+    HeapFree(GetProcessHeap(), 0, ComponentId);
     HeapFree(GetProcessHeap(), 0, DeviceName);
     HeapFree(GetProcessHeap(), 0, ExportName);
     if (hKey != NULL)
@@ -373,6 +404,7 @@ cleanup:
         RegCloseKey(hLinkageKey);
     if (hConnectionKey != NULL)
         RegCloseKey(hConnectionKey);
+
     return rc;
 }
 
@@ -558,8 +590,6 @@ cleanup:
     HeapFree(GetProcessHeap(), 0, BusType);
     HeapFree(GetProcessHeap(), 0, UuidString);
 
-    if (rc == ERROR_SUCCESS)
-        rc = ERROR_DI_DO_DEFAULT;
     TRACE("Returning 0x%lx\n", rc);
     return rc;
 }