Index: /trunk/include/VBox/VBoxNetCfg-win.h
===================================================================
--- /trunk/include/VBox/VBoxNetCfg-win.h	(revision 77803)
+++ /trunk/include/VBox/VBoxNetCfg-win.h	(revision 77804)
@@ -85,9 +85,9 @@
 
 #ifndef VBOXNETCFG_DELAYEDRENAME
-VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile,
+VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile, IN BSTR bstrDesiredName,
                                                                         OUT GUID *pGuid, OUT BSTR *lppszName,
                                                                         OUT BSTR *pErrMsg);
 #else /* VBOXNETCFG_DELAYEDRENAME */
-VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile,
+VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile, IN BSTR bstrDesiredName,
                                                                         OUT GUID *pGuid, OUT BSTR *lppszId,
                                                                         OUT BSTR *pErrMsg);
Index: /trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp
===================================================================
--- /trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp	(revision 77803)
+++ /trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp	(revision 77804)
@@ -2580,4 +2580,45 @@
 }
 
+static bool vboxNetCfgWinDetectStaleConnection(PCWSTR pName)
+{
+    HKEY hkeyConnection, hkeyAdapter, hkeyAdapters;
+    WCHAR wszAdaptersKeyName[] = L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
+    WCHAR wszAdapterSubKeyName[MAX_PATH];
+    LSTATUS status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, wszAdaptersKeyName, 0, KEY_ALL_ACCESS, &hkeyAdapters);
+    if (status != ERROR_SUCCESS)
+        return false;
+
+    bool fFailureImminent = false;
+    for (DWORD i = 0; !fFailureImminent; ++i)
+    {
+        DWORD cbName = MAX_PATH;
+        status = RegEnumKeyEx(hkeyAdapters, i, wszAdapterSubKeyName, &cbName, NULL, NULL, NULL, NULL);
+        // if (status == ERROR_NO_MORE_ITEMS)
+        //     break;
+        if (status != ERROR_SUCCESS)
+            break;
+
+        status = RegOpenKeyEx(hkeyAdapters, wszAdapterSubKeyName, 0, KEY_ALL_ACCESS, &hkeyAdapter);
+        if (status == ERROR_SUCCESS)
+        {
+            status = RegOpenKeyEx(hkeyAdapter, L"Connection", 0, KEY_ALL_ACCESS, &hkeyConnection);
+            if (status == ERROR_SUCCESS)
+            {
+                WCHAR wszName[MAX_PATH];
+                cbName = MAX_PATH;
+                status = RegQueryValueEx(hkeyConnection, L"Name", NULL, NULL, (LPBYTE)wszName, &cbName);
+                if (status == ERROR_SUCCESS)
+                    if (wcsicmp(wszName, pName) == 0)
+                        fFailureImminent = true;
+                RegCloseKey(hkeyConnection);
+            }
+            RegCloseKey(hkeyAdapter);
+        }
+    }
+    RegCloseKey(hkeyAdapters);
+
+    return fFailureImminent;
+}
+
 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinRenameConnection (LPWSTR pGuid, PCWSTR NewName)
 {
@@ -2586,4 +2627,11 @@
     HRESULT status;
 
+    /*
+     * Before attempting to rename the connection, check if there is a stale
+     * connection with the same name. We must return ok, so the rest of
+     * configuration process proceeds normally.
+     */
+    if (vboxNetCfgWinDetectStaleConnection(NewName))
+        return S_OK;
     /* First try the IShellFolder interface, which was unimplemented
      * for the network connections folder before XP. */
@@ -2881,5 +2929,27 @@
 }
 
-static HRESULT vboxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile,
+typedef struct {
+    BSTR bstrName;
+    GUID *pGuid;
+    HRESULT hr;
+} RENAMING_CONTEXT;
+
+static BOOL vboxNetCfgWinRenameHostOnlyNetworkInterface(IN INetCfg *pNc, IN INetCfgComponent *pNcc, PVOID pContext)
+{
+    RT_NOREF1(pNc);
+    RENAMING_CONTEXT *pParams = (RENAMING_CONTEXT *)pContext;
+
+    GUID guid;
+    pParams->hr = pNcc->GetInstanceGuid(&guid);
+    if ( pParams->hr == S_OK && guid == *pParams->pGuid)
+    {
+        /* Located our component, rename it */
+        pParams->hr = pNcc->SetDisplayName(pParams->bstrName);
+        return FALSE;
+    }
+    return TRUE;
+}
+
+static HRESULT vboxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile, IN BSTR bstrDesiredName,
                                                            OUT GUID *pGuid, OUT BSTR *lppszName, OUT BSTR *pErrMsg)
 {
@@ -3326,5 +3396,69 @@
         INetCfg *pNetCfg = NULL;
         LPWSTR lpszApp = NULL;
+
+        RENAMING_CONTEXT context;
+        context.hr = E_FAIL;
+
+        if (pGuid)
+        {
+            hrc = CLSIDFromString(pWCfgGuidString, (LPCLSID)pGuid);
+            if (FAILED(hrc))
+                NonStandardLogFlow(("CLSIDFromString failed, hrc (0x%x)\n", hrc));
+        }
+
+        hr = VBoxNetCfgWinQueryINetCfg(&pNetCfg, TRUE, L"VirtualBox Host-Only Creation",
+                                       30 * 1000, /* on Vista we often get 6to4svc.dll holding the lock, wait for 30 sec.  */
+                                       /** @todo special handling for 6to4svc.dll ???, i.e. several retrieves */
+                                       &lpszApp);
+        if (hr == S_OK)
+        {
+            if (SysStringLen(bstrDesiredName) != 0)
+            {
+                /* Rename only if the desired name has been provided */
+                context.bstrName = bstrDesiredName;
+                context.pGuid = pGuid;
+                hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg,
+                                                       &GUID_DEVCLASS_NET,
+                                                       vboxNetCfgWinRenameHostOnlyNetworkInterface,
+                                                       &context);
+            }
+            if (SUCCEEDED(hr))
+                hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg,
+                                                       &GUID_DEVCLASS_NETSERVICE,
+                                                       vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,
+                                                       pGuid);
+            if (SUCCEEDED(hr))
+                hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg,
+                                                       &GUID_DEVCLASS_NETTRANS,
+                                                       vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,
+                                                       pGuid);
+            if (SUCCEEDED(hr))
+                hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg,
+                                                       &GUID_DEVCLASS_NETCLIENT,
+                                                       vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,
+                                                       pGuid);
+            if (SUCCEEDED(hr))
+            {
+                hr = pNetCfg->Apply();
+            }
+            else
+                NonStandardLogFlow(("Enumeration failed, hr 0x%x\n", hr));
+            VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);
+        }
+        else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszApp)
+        {
+            NonStandardLogFlow(("Application %ws is holding the lock, failed\n", lpszApp));
+            CoTaskMemFree(lpszApp);
+        }
+        else
+            NonStandardLogFlow(("VBoxNetCfgWinQueryINetCfg failed, hr 0x%x\n", hr));
+
 #ifndef VBOXNETCFG_DELAYEDRENAME
+        if (SUCCEEDED(hr) && SUCCEEDED(context.hr))
+        {
+            /* The device has been successfully renamed, replace the name now. */
+            wcscpy_s(DevName, RT_ELEMENTS(DevName), bstrDesiredName);
+        }
+
         WCHAR ConnectionName[128];
         ULONG cbName = sizeof(ConnectionName);
@@ -3343,50 +3477,4 @@
             }
         }
-
-        if (pGuid)
-        {
-            hrc = CLSIDFromString(pWCfgGuidString, (LPCLSID)pGuid);
-            if (FAILED(hrc))
-                NonStandardLogFlow(("CLSIDFromString failed, hrc (0x%x)\n", hrc));
-        }
-
-        hr = VBoxNetCfgWinQueryINetCfg(&pNetCfg, TRUE, L"VirtualBox Host-Only Creation",
-                                       30 * 1000, /* on Vista we often get 6to4svc.dll holding the lock, wait for 30 sec.  */
-                                       /** @todo special handling for 6to4svc.dll ???, i.e. several retrieves */
-                                       &lpszApp);
-        if (hr == S_OK)
-        {
-            hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg,
-                                                   &GUID_DEVCLASS_NETSERVICE,
-                                                   vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,
-                                                   pGuid);
-            if (SUCCEEDED(hr))
-            {
-                hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg,
-                                                       &GUID_DEVCLASS_NETTRANS,
-                                                       vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,
-                                                       pGuid);
-                if (SUCCEEDED(hr))
-                    hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg,
-                                                           &GUID_DEVCLASS_NETCLIENT,
-                                                           vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,
-                                                           pGuid);
-            }
-
-            if (SUCCEEDED(hr))
-            {
-                hr = pNetCfg->Apply();
-            }
-            else
-                NonStandardLogFlow(("Enumeration failed, hr 0x%x\n", hr));
-            VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);
-        }
-        else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszApp)
-        {
-            NonStandardLogFlow(("Application %ws is holding the lock, failed\n", lpszApp));
-            CoTaskMemFree(lpszApp);
-        }
-        else
-            NonStandardLogFlow(("VBoxNetCfgWinQueryINetCfg failed, hr 0x%x\n", hr));
     }
 
@@ -3397,8 +3485,8 @@
 }
 
-VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile,
+VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile, IN BSTR pwsDesiredName,
                                                                         OUT GUID *pGuid, OUT BSTR *lppszName, OUT BSTR *pErrMsg)
 {
-    HRESULT hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, pGuid, lppszName, pErrMsg);
+    HRESULT hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, pwsDesiredName, pGuid, lppszName, pErrMsg);
     if (hrc == E_ABORT)
     {
@@ -3412,5 +3500,5 @@
          * See @bugref{7973} for details.
          */
-        hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, pGuid, lppszName, pErrMsg);
+        hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, pwsDesiredName, pGuid, lppszName, pErrMsg);
         if (hrc == E_ABORT)
         {
@@ -3435,5 +3523,5 @@
                         Sleep(1000);
                     CloseServiceHandle(hService);
-                    hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, pGuid, lppszName, pErrMsg);
+                    hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, pwsDesiredName, pGuid, lppszName, pErrMsg);
                 }
                 else
Index: /trunk/src/VBox/Installer/win/InstallHelper/VBoxInstallHelper.cpp
===================================================================
--- /trunk/src/VBox/Installer/win/InstallHelper/VBoxInstallHelper.cpp	(revision 77803)
+++ /trunk/src/VBox/Installer/win/InstallHelper/VBoxInstallHelper.cpp	(revision 77804)
@@ -1072,7 +1072,7 @@
 #ifdef VBOXNETCFG_DELAYEDRENAME
             BSTR devId;
-            hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface(pwszInfPath, fIsFile, &guid, &devId, NULL);
+            hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface(pwszInfPath, fIsFile, NULL, &guid, &devId, NULL);
 #else /* !VBOXNETCFG_DELAYEDRENAME */
-            hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface(pwszInfPath, fIsFile, &guid, NULL, NULL);
+            hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface(pwszInfPath, fIsFile, NULL, &guid, NULL, NULL);
 #endif /* !VBOXNETCFG_DELAYEDRENAME */
             logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface returns 0x%x", hr);
Index: /trunk/src/VBox/Main/include/HostImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/HostImpl.h	(revision 77803)
+++ /trunk/src/VBox/Main/include/HostImpl.h	(revision 77804)
@@ -85,4 +85,10 @@
 
     static void i_generateMACAddress(Utf8Str &mac);
+
+#ifdef RT_OS_WINDOWS
+    HRESULT i_updatePersistentConfigForHostOnlyAdapters(void);
+    HRESULT i_removePersistentConfig(const Bstr &bstrGuid);
+#endif /* RT_OS_WINDOWS */
+
 
 private:
Index: /trunk/src/VBox/Main/include/HostNetworkInterfaceImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/HostNetworkInterfaceImpl.h	(revision 77803)
+++ /trunk/src/VBox/Main/include/HostNetworkInterfaceImpl.h	(revision 77804)
@@ -50,4 +50,7 @@
 
     HRESULT i_setVirtualBox(VirtualBox *pVirtualBox);
+#ifdef RT_OS_WINDOWS
+    HRESULT i_updatePersistentConfig();
+#endif /* RT_OS_WINDOWS */
 
 #ifdef VBOX_WITH_RESOURCE_USAGE_API
@@ -84,4 +87,14 @@
 
     Utf8Str i_composeNetworkName(const Utf8Str szShortName);
+
+#if defined(RT_OS_WINDOWS)
+    HRESULT eraseAdapterConfigParameter(const char *szParamName);
+    HRESULT saveAdapterConfigParameter(const char *szParamName, const Utf8Str& strValue);
+    HRESULT saveAdapterConfigIPv4Dhcp();
+    HRESULT saveAdapterConfigIPv4(ULONG addr, ULONG mask);
+    HRESULT saveAdapterConfigIPv6(const Utf8Str& addr, ULONG prefix);
+    HRESULT saveAdapterConfig();
+    bool    isInConfigFile();
+#endif /* defined(RT_OS_WINDOWS) */
 
     const Utf8Str mInterfaceName;
Index: /trunk/src/VBox/Main/include/netif.h
===================================================================
--- /trunk/src/VBox/Main/include/netif.h	(revision 77803)
+++ /trunk/src/VBox/Main/include/netif.h	(revision 77804)
@@ -97,5 +97,9 @@
 int NetIfEnableStaticIpConfigV6(VirtualBox *pVBox, HostNetworkInterface *pIf, const Utf8Str &aOldIPV6Address, const Utf8Str &aIPV6Address, ULONG aIPV6MaskPrefixLength);
 int NetIfEnableDynamicIpConfig(VirtualBox *pVBox, HostNetworkInterface * pIf);
+#if defined(RT_OS_WINDOWS)
+int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress, IN_BSTR bstrName = NULL);
+#else /* !defined(RT_OS_WINDOWS) */
 int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress, const char *pszName = NULL);
+#endif /* !defined(RT_OS_WINDOWS) */
 int NetIfRemoveHostOnlyNetworkInterface(VirtualBox *pVBox, const Guid &aId, IProgress **aProgress);
 int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *);
Index: /trunk/src/VBox/Main/src-server/HostImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/HostImpl.cpp	(revision 77803)
+++ /trunk/src/VBox/Main/src-server/HostImpl.cpp	(revision 77804)
@@ -54,7 +54,5 @@
 #endif
 
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
-# include <set>
-#endif
+#include <set>
 
 #ifdef VBOX_WITH_RESOURCE_USAGE_API
@@ -186,5 +184,6 @@
         :
           fDVDDrivesListBuilt(false),
-          fFloppyDrivesListBuilt(false)
+          fFloppyDrivesListBuilt(false),
+          fPersistentConfigUpToDate(false)
     {};
 
@@ -231,4 +230,7 @@
     /** Host's DNS informaton fetching */
     HostDnsMonitorProxy     hostDnsMonitorProxy;
+
+    /** Startup syncing of persistent config in extra data */
+    bool                    fPersistentConfigUpToDate;
 };
 
@@ -644,4 +646,150 @@
 #endif /* defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT) */
 
+#if defined(RT_OS_WINDOWS)
+struct HostOnlyInfo
+{
+    HostOnlyInfo() : fDhcpEnabled(false), uIPv6PrefixLength(0) {};
+
+    Bstr bstrName;
+    bool fDhcpEnabled;
+    Bstr strIPv4Address;
+    Bstr strIPv4NetMask;
+    Bstr strIPv6Address;
+    ULONG uIPv6PrefixLength;
+};
+
+typedef std::map<Utf8Str, HostOnlyInfo*> GUID_TO_HOST_ONLY_INFO;
+
+HRESULT Host::i_updatePersistentConfigForHostOnlyAdapters(void)
+{
+    /* No need to do the sync twice */
+    if (m->fPersistentConfigUpToDate)
+        return S_OK;
+    m->fPersistentConfigUpToDate = true;
+    bool fChangesMade = false;
+
+    /* Extract the list of configured host-only interfaces */
+    GUID_TO_HOST_ONLY_INFO aSavedAdapters;
+    SafeArray<BSTR> aGlobalExtraDataKeys;
+    HRESULT hrc = m->pParent->GetExtraDataKeys(ComSafeArrayAsOutParam(aGlobalExtraDataKeys));
+    AssertMsg(SUCCEEDED(hrc), ("VirtualBox::GetExtraDataKeys failed with %Rhrc\n", hrc));
+    for (size_t i = 0; i < aGlobalExtraDataKeys.size(); ++i)
+    {
+        Utf8Str strKey = aGlobalExtraDataKeys[i];
+
+        if (strKey.startsWith("HostOnly/{"))
+        {
+            Bstr bstrValue;
+            HRESULT hrc = m->pParent->GetExtraData(aGlobalExtraDataKeys[i], bstrValue.asOutParam());
+            if (hrc != S_OK)
+                continue;
+
+            Utf8Str strGuid = strKey.substr(10, 36); /* Skip "HostOnly/{" */
+            if (aSavedAdapters.find(strGuid) == aSavedAdapters.end())
+                aSavedAdapters[strGuid] = new HostOnlyInfo();
+
+            if (strKey.endsWith("}/Name"))
+                aSavedAdapters[strGuid]->bstrName = bstrValue;
+            else if (strKey.endsWith("}/IPAddress"))
+            {
+                if (bstrValue == "DHCP")
+                    aSavedAdapters[strGuid]->fDhcpEnabled = true;
+                else
+                    aSavedAdapters[strGuid]->strIPv4Address = bstrValue;
+            }
+            else if (strKey.endsWith("}/IPNetMask"))
+                aSavedAdapters[strGuid]->strIPv4NetMask = bstrValue;
+            else if (strKey.endsWith("}/IPV6Address"))
+                aSavedAdapters[strGuid]->strIPv6Address = bstrValue;
+            else if (strKey.endsWith("}/IPV6PrefixLen"))
+                aSavedAdapters[strGuid]->uIPv6PrefixLength = Utf8Str(bstrValue).toUInt32();
+        }
+    }
+
+    /* Go over the list of existing adapters and update configs saved in extra data */
+    std::set<Bstr> aKnownNames;
+    for (HostNetworkInterfaceList::iterator it = m->llNetIfs.begin(); it != m->llNetIfs.end(); ++it)
+    {
+        /* Get type */
+        HostNetworkInterfaceType_T t;
+        hrc = (*it)->COMGETTER(InterfaceType)(&t);
+        if (FAILED(hrc) || t != HostNetworkInterfaceType_HostOnly)
+            continue;
+        /* Get id */
+        Bstr bstrGuid;
+        hrc = (*it)->COMGETTER(Id)(bstrGuid.asOutParam());
+        if (FAILED(hrc))
+            continue;
+        /* Get name */
+        Bstr bstrName;
+        hrc = (*it)->COMGETTER(Name)(bstrName.asOutParam());
+        if (FAILED(hrc))
+            continue;
+
+        /* Remove adapter from map as it does not need any further processing */
+        aSavedAdapters.erase(Utf8Str(bstrGuid));
+        /* Add adapter name to the list of known names, so we won't attempt to create adapters with the same name */
+        aKnownNames.insert(bstrName);
+        /* Make sure our extra data contains the latest config */
+        hrc = (*it)->i_updatePersistentConfig();
+        if (hrc != S_OK)
+            break;
+    }
+
+    /* The following loop not only creates missing adapters, it destroys HostOnlyInfo objects contained in the map as well */
+    for (GUID_TO_HOST_ONLY_INFO::iterator it = aSavedAdapters.begin(); it != aSavedAdapters.end(); ++it)
+    {
+        Utf8Str strGuid = (*it).first;
+        HostOnlyInfo *pInfo = (*it).second;
+        /* We create adapters only if we haven't seen one with the same name */
+        if (aKnownNames.find(pInfo->bstrName) == aKnownNames.end())
+        {
+            /* There is no adapter with such name yet, create it */
+            ComPtr<IHostNetworkInterface> hif;
+            ComPtr<IProgress> progress;
+
+            int rc = NetIfCreateHostOnlyNetworkInterface(m->pParent, hif.asOutParam(), progress.asOutParam(), pInfo->bstrName.raw());
+            if (RT_FAILURE(rc))
+            {
+                LogRel(("Failed to create host-only adapter (%d)\n", rc));
+                hrc = E_UNEXPECTED;
+                break;
+            }
+            /* Wait for the adapter to get configured completely, before we modify IP addresses. */
+            progress->WaitForCompletion(-1);
+            fChangesMade = true;
+            if (pInfo->fDhcpEnabled)
+            {
+                hrc = hif->EnableDynamicIPConfig();
+                LogRel(("EnableDynamicIPConfig returned 0x%x\n", hrc));
+            }
+            else
+            {
+                hrc = hif->EnableStaticIPConfig(pInfo->strIPv4Address.raw(), pInfo->strIPv4NetMask.raw());
+                LogRel(("EnableStaticIpConfig returned 0x%x\n", hrc));
+            }
+# if 0
+            /* Somehow HostNetworkInterface::EnableStaticIPConfigV6 is not implemented yet. */
+            if (SUCCEEDED(hrc))
+            {
+                hrc = hif->EnableStaticIPConfigV6(pInfo->strIPv6Address.raw(), pInfo->uIPv6PrefixLength);
+                LogRel(("EnableStaticIPConfigV6 returned 0x%x\n", hrc));
+            }
+# endif
+            /* Now we have seen this name */
+            aKnownNames.insert(pInfo->bstrName);
+            /* Drop the old config as the newly created adapter has different GUID */
+            i_removePersistentConfig(strGuid);
+        }
+        delete pInfo;
+    }
+    /* Update the list again if we have created some adapters */
+    if (SUCCEEDED(hrc) && fChangesMade)
+        hrc = i_updateNetIfList();
+
+    return hrc;
+}
+#endif /* defined(RT_OS_WINDOWS) */
+
 /**
  * Returns a list of host network interfaces.
@@ -660,4 +808,12 @@
         return rc;
     }
+#if defined(RT_OS_WINDOWS)
+    rc = i_updatePersistentConfigForHostOnlyAdapters();
+    if (FAILED(rc))
+    {
+        LogRel(("Failed to update persistent config for host-only adapters with rc=%Rhrc\n", rc));
+        return rc;
+    }
+#endif /* defined(RT_OS_WINDOWS) */
 
     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
@@ -1334,5 +1490,5 @@
                                                tmpMask.raw());
         ComAssertComRCRet(hrc, hrc);
-#endif
+#endif /* !defined(RT_OS_WINDOWS) */
     }
 
@@ -1342,4 +1498,17 @@
 #endif
 }
+
+
+#ifdef RT_OS_WINDOWS
+HRESULT Host::i_removePersistentConfig(const Bstr &bstrGuid)
+{
+    HRESULT hrc = m->pParent->SetExtraData(BstrFmt("HostOnly/{%ls}/Name", bstrGuid.raw()).raw(), NULL);
+    if (SUCCEEDED(hrc)) hrc = m->pParent->SetExtraData(BstrFmt("HostOnly/{%ls}/IPAddress", bstrGuid.raw()).raw(), NULL);
+    if (SUCCEEDED(hrc)) hrc = m->pParent->SetExtraData(BstrFmt("HostOnly/{%ls}/IPNetMask", bstrGuid.raw()).raw(), NULL);
+    if (SUCCEEDED(hrc)) hrc = m->pParent->SetExtraData(BstrFmt("HostOnly/{%ls}/IPV6Address", bstrGuid.raw()).raw(), NULL);
+    if (SUCCEEDED(hrc)) hrc = m->pParent->SetExtraData(BstrFmt("HostOnly/{%ls}/IPV6PrefixLen", bstrGuid.raw()).raw(), NULL);
+    return hrc;
+}
+#endif /* RT_OS_WINDOWS */
 
 HRESULT Host::removeHostOnlyNetworkInterface(const com::Guid &aId,
@@ -1371,8 +1540,13 @@
     {
         /* Drop configuration parameters for removed interface */
+#ifdef RT_OS_WINDOWS
+        rc = i_removePersistentConfig(Utf8StrFmt("%RTuuid", &aId));
+        LogRel(("i_removePersistentConfig(%RTuuid) returned %d\n", &aId, r));
+#else /* !RT_OS_WINDOWS */
         rc = m->pParent->SetExtraData(BstrFmt("HostOnly/%ls/IPAddress", name.raw()).raw(), NULL);
         rc = m->pParent->SetExtraData(BstrFmt("HostOnly/%ls/IPNetMask", name.raw()).raw(), NULL);
         rc = m->pParent->SetExtraData(BstrFmt("HostOnly/%ls/IPV6Address", name.raw()).raw(), NULL);
         rc = m->pParent->SetExtraData(BstrFmt("HostOnly/%ls/IPV6NetMask", name.raw()).raw(), NULL);
+#endif /* !RT_OS_WINDOWS */
 
         return S_OK;
@@ -1563,4 +1737,12 @@
         return rc;
     }
+#if defined(RT_OS_WINDOWS)
+    rc = i_updatePersistentConfigForHostOnlyAdapters();
+    if (FAILED(rc))
+    {
+        LogRel(("Failed to update persistent config for host-only adapters with rc=%Rhrc\n", rc));
+        return rc;
+    }
+#endif /* defined(RT_OS_WINDOWS) */
 
     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
@@ -1598,4 +1780,12 @@
         return rc;
     }
+#if defined(RT_OS_WINDOWS)
+    rc = i_updatePersistentConfigForHostOnlyAdapters();
+    if (FAILED(rc))
+    {
+        LogRel(("Failed to update persistent config for host-only adapters with rc=%Rhrc\n", rc));
+        return rc;
+    }
+#endif /* defined(RT_OS_WINDOWS) */
 
     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
@@ -1628,4 +1818,12 @@
         return rc;
     }
+#if defined(RT_OS_WINDOWS)
+    rc = i_updatePersistentConfigForHostOnlyAdapters();
+    if (FAILED(rc))
+    {
+        LogRel(("Failed to update persistent config for host-only adapters with rc=%Rhrc\n", rc));
+        return rc;
+    }
+#endif /* defined(RT_OS_WINDOWS) */
 
     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
Index: /trunk/src/VBox/Main/src-server/HostNetworkInterfaceImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/HostNetworkInterfaceImpl.cpp	(revision 77803)
+++ /trunk/src/VBox/Main/src-server/HostNetworkInterfaceImpl.cpp	(revision 77804)
@@ -156,4 +156,88 @@
 
 #ifdef VBOX_WITH_HOSTNETIF_API
+
+#if defined(RT_OS_WINDOWS)
+HRESULT HostNetworkInterface::saveAdapterConfigParameter(const char *szParamName, const Utf8Str &strValue)
+{
+    AssertReturn(mVirtualBox != NULL, E_POINTER);
+    return mVirtualBox->SetExtraData(Bstr(Utf8StrFmt("HostOnly/{%RTuuid}/%s", mGuid, szParamName)).raw(), Bstr(strValue).raw());
+}
+
+HRESULT HostNetworkInterface::eraseAdapterConfigParameter(const char *szParamName)
+{
+    AssertReturn(mVirtualBox != NULL, E_POINTER);
+    return mVirtualBox->SetExtraData(Bstr(Utf8StrFmt("HostOnly/{%RTuuid}/%s", mGuid, szParamName)).raw(), NULL);
+}
+
+HRESULT HostNetworkInterface::saveAdapterConfigIPv4Dhcp()
+{
+    HRESULT hrc = saveAdapterConfigParameter("IPAddress", "DHCP");
+    if (hrc == S_OK)
+        hrc = eraseAdapterConfigParameter("IPNetMask");
+    return hrc;
+}
+
+HRESULT HostNetworkInterface::saveAdapterConfigIPv4(ULONG addr, ULONG mask)
+{
+    HRESULT hrc = saveAdapterConfigParameter("IPAddress", Utf8StrFmt("%RTnaipv4", addr));
+    if (hrc == S_OK)
+        hrc = saveAdapterConfigParameter("IPNetMask", Utf8StrFmt("%RTnaipv4", mask));
+    return hrc;
+}
+
+HRESULT HostNetworkInterface::saveAdapterConfigIPv6(const Utf8Str& addr, ULONG prefix)
+{
+    HRESULT hrc = saveAdapterConfigParameter("IPV6Address", addr);
+    if (hrc == S_OK)
+        hrc = saveAdapterConfigParameter("IPV6PrefixLen", Utf8StrFmt("%u", prefix));
+    return hrc;
+}
+
+bool HostNetworkInterface::isInConfigFile(void)
+{
+    /* We care about host-only adapters only */
+    if (mIfType != HostNetworkInterfaceType_HostOnly)
+        return true;
+
+    Assert(mVirtualBox != NULL);
+    if (mVirtualBox == NULL)
+        return false; /* Trigger config update, which will fail with proper return code */
+    Bstr tmpName;
+    mVirtualBox->GetExtraData(Bstr(Utf8StrFmt("HostOnly/{%RTuuid}/Name", mGuid)).raw(), tmpName.asOutParam());
+    return (tmpName.isNotEmpty() && tmpName == mInterfaceName);
+
+}
+
+HRESULT HostNetworkInterface::saveAdapterConfig(void)
+{
+    /* We care about host-only adapters only */
+    if (mIfType != HostNetworkInterfaceType_HostOnly)
+        return true;
+
+    HRESULT hrc = saveAdapterConfigParameter("Name", mInterfaceName.c_str());
+    if (FAILED(hrc))
+        return hrc;
+    if (m.dhcpEnabled)
+        hrc = saveAdapterConfigIPv4Dhcp();
+    else
+        hrc = saveAdapterConfigIPv4(m.IPAddress, m.networkMask);
+    if (SUCCEEDED(hrc))
+        hrc = saveAdapterConfigIPv6(m.IPV6Address.c_str(), m.IPV6NetworkMaskPrefixLength);
+    return hrc;
+}
+
+HRESULT HostNetworkInterface::i_updatePersistentConfig(void)
+{
+    if (mVirtualBox == NULL)
+        return E_POINTER;
+
+    HRESULT hrc = S_OK;
+    if (!isInConfigFile())
+    {
+        hrc = saveAdapterConfig();
+    }
+    return hrc;
+}
+#endif /* defined(RT_OS_WINDOWS) */
 
 HRESULT HostNetworkInterface::updateConfig()
@@ -465,4 +549,8 @@
             {
                 m.realIPAddress = 0;
+#if defined(RT_OS_WINDOWS)
+                eraseAdapterConfigParameter("IPAddress");
+                eraseAdapterConfigParameter("IPNetMask");
+#else /* !defined(RT_OS_WINDOWS) */
                 if (FAILED(mVirtualBox->SetExtraData(BstrFmt("HostOnly/%s/IPAddress",
                                                              mInterfaceName.c_str()).raw(), NULL)))
@@ -471,4 +559,5 @@
                                                              mInterfaceName.c_str()).raw(), NULL)))
                     return E_FAIL;
+#endif /* !defined(RT_OS_WINDOWS) */
                 return S_OK;
             }
@@ -495,4 +584,7 @@
                 m.realIPAddress   = ip;
                 m.realNetworkMask = mask;
+#if defined(RT_OS_WINDOWS)
+                saveAdapterConfigIPv4(ip, mask);
+#else /* !defined(RT_OS_WINDOWS) */
                 if (FAILED(mVirtualBox->SetExtraData(BstrFmt("HostOnly/%s/IPAddress",
                                                              mInterfaceName.c_str()).raw(),
@@ -503,4 +595,5 @@
                                                      Bstr(aNetworkMask).raw())))
                     return E_FAIL;
+#endif /* !defined(RT_OS_WINDOWS) */
                 return S_OK;
             }
@@ -566,4 +659,7 @@
             m.realIPV6Address = aIPV6Address;
             m.realIPV6PrefixLength = aIPV6NetworkMaskPrefixLength;
+#if defined(RT_OS_WINDOWS)
+            saveAdapterConfigIPv6(Bstr(aIPV6Address).raw(), aIPV6NetworkMaskPrefixLength);
+#else /* !defined(RT_OS_WINDOWS) */
             if (FAILED(mVirtualBox->SetExtraData(BstrFmt("HostOnly/%s/IPV6Address",
                                                          mInterfaceName.c_str()).raw(),
@@ -573,4 +669,5 @@
                                                          mInterfaceName.c_str()).raw(),
                                                  BstrFmt("%u", aIPV6NetworkMaskPrefixLength).raw())))
+#endif /* !defined(RT_OS_WINDOWS) */
                 return E_FAIL;
         }
Index: /trunk/src/VBox/Main/src-server/win/NetIf-win.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/win/NetIf-win.cpp	(revision 77803)
+++ /trunk/src/VBox/Main/src-server/win/NetIf-win.cpp	(revision 77804)
@@ -302,6 +302,6 @@
             vrc = aClient->write(d->msgCode);
             if (RT_FAILURE(vrc)) break;
-//            vrc = aClient->write(Utf8Str(d->name));
-//            if (RT_FAILURE(vrc)) break;
+            vrc = aClient->write(Utf8Str(d->name));
+            if (RT_FAILURE(vrc)) break;
 
             /* wait for a reply */
@@ -337,4 +337,6 @@
                             {
                                 rc = d->iface->updateConfig();
+                                if (SUCCEEDED(rc))
+                                    rc = d->iface->i_updatePersistentConfig();
                             }
                         }
@@ -678,7 +680,7 @@
             LogFlowFunc(("CreateHostOnlyNetworkInterface:\n"));
 
-//            Utf8Str name;
-//            vrc = aClient->read(name);
-//            if (RT_FAILURE(vrc)) break;
+            Utf8Str desiredName;
+            vrc = aClient->read(desiredName);
+            if (RT_FAILURE(vrc)) break;
 
             Guid guid;
@@ -689,8 +691,8 @@
 #ifdef VBOXNETCFG_DELAYEDRENAME
             Bstr devId;
-            hrc = VBoxNetCfgWinCreateHostOnlyNetworkInterface(NULL, false, guid.asOutParam(), devId.asOutParam(),
+            hrc = VBoxNetCfgWinCreateHostOnlyNetworkInterface(NULL, false, Bstr(desiredName).raw(), guid.asOutParam(), devId.asOutParam(),
                                                               bstrErr.asOutParam());
 #else /* !VBOXNETCFG_DELAYEDRENAME */
-            hrc = VBoxNetCfgWinCreateHostOnlyNetworkInterface(NULL, false, guid.asOutParam(), name.asOutParam(),
+            hrc = VBoxNetCfgWinCreateHostOnlyNetworkInterface(NULL, false, Bstr(desiredName).raw(), guid.asOutParam(), name.asOutParam(),
                                                               bstrErr.asOutParam());
 #endif /* !VBOXNETCFG_DELAYEDRENAME */
@@ -1146,7 +1148,6 @@
                                         IHostNetworkInterface **aHostNetworkInterface,
                                         IProgress **aProgress,
-                                        const char *pszName)
-{
-    RT_NOREF(pszName);
+                                        IN_BSTR aName)
+{
 #ifndef VBOX_WITH_NETFLT
     return VERR_NOT_IMPLEMENTED;
@@ -1177,5 +1178,5 @@
 
             d->msgCode = SVCHlpMsg::CreateHostOnlyNetworkInterface;
-//            d->name = aName;
+            d->name = aName;
             d->iface = iface;
             d->vBox = pVirtualBox;
