Index: /trunk/src/VBox/NetworkServices/DHCP/VBoxNetDHCP.cpp
===================================================================
--- /trunk/src/VBox/NetworkServices/DHCP/VBoxNetDHCP.cpp	(revision 54699)
+++ /trunk/src/VBox/NetworkServices/DHCP/VBoxNetDHCP.cpp	(revision 54700)
@@ -93,4 +93,5 @@
 
     int                 init();
+    void                done();
     void                usage(void) { /* XXX: document options */ };
     int                 parseOpt(int rc, const RTGETOPTUNION& getOptVal);
@@ -129,5 +130,6 @@
 
     /** Listener for Host DNS changes */
-    ComPtr<NATNetworkListenerImpl> m_vboxListener;
+    ComNatListenerPtr m_VBoxListener;
+    ComNatListenerPtr m_VBoxClientListener;
 
     NetworkManager *m_NetworkManager;
@@ -303,4 +305,9 @@
 }
 
+void VBoxNetDhcp::done()
+{
+    destroyNatListener(m_VBoxListener, virtualbox);
+    destroyClientListener(m_VBoxClientListener, virtualboxClient);
+}
 
 int  VBoxNetDhcp::processUDP(void *pv, size_t cbPv)
@@ -517,9 +524,18 @@
     AssertMsgRCReturn(rc, ("Wasn't able to fetch Dns info"), rc);
 
-    ComEventTypeArray aVBoxEvents;
-    aVBoxEvents.push_back(VBoxEventType_OnHostNameResolutionConfigurationChange);
-    aVBoxEvents.push_back(VBoxEventType_OnNATNetworkStartStop);
-    rc = createNatListener(m_vboxListener, virtualbox, this, aVBoxEvents);
-    AssertRCReturn(rc, rc);
+    {
+        ComEventTypeArray eventTypes;
+        eventTypes.push_back(VBoxEventType_OnHostNameResolutionConfigurationChange);
+        eventTypes.push_back(VBoxEventType_OnNATNetworkStartStop);
+        rc = createNatListener(m_VBoxListener, virtualbox, this, eventTypes);
+        AssertRCReturn(rc, rc);
+    }
+
+    {
+        ComEventTypeArray eventTypes;
+        eventTypes.push_back(VBoxEventType_OnVBoxSVCAvailabilityChanged);
+        rc = createClientListener(m_VBoxClientListener, virtualboxClient, this, eventTypes);
+        AssertRCReturn(rc, rc);
+    }
 
     RTNETADDRIPV4 LowerAddress;
@@ -588,5 +604,4 @@
     return VINF_SUCCESS;
 }
-
 
 HRESULT VBoxNetDhcp::HandleEvent(VBoxEventType_T aEventType, IEvent *pEvent)
@@ -607,4 +622,10 @@
             break;
         }
+
+        case VBoxEventType_OnVBoxSVCAvailabilityChanged:
+        {
+            shutdown();
+            break;
+        }
     }
 
@@ -648,4 +669,6 @@
     g_pDhcp = pDhcp;
     rc = pDhcp->run();
+    pDhcp->done();
+
     g_pDhcp = NULL;
     delete pDhcp;
Index: /trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp
===================================================================
--- /trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp	(revision 54699)
+++ /trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp	(revision 54700)
@@ -17,4 +17,6 @@
 
 /* Must be included before winutils.h (lwip/def.h), otherwise Windows build breaks. */
+#define LOG_GROUP LOG_GROUP_NAT_SERVICE
+
 #include <iprt/cpp/mem.h>
 
@@ -53,5 +55,4 @@
 #include <iprt/semaphore.h>
 #include <iprt/cpp/utils.h>
-#define LOG_GROUP LOG_GROUP_NAT_SERVICE
 #include <VBox/log.h>
 
@@ -167,8 +168,9 @@
     /* Our NAT network descriptor in Main */
     ComPtr<INATNetwork> m_net;
-    ComNatListenerPtr m_listener;
-
     ComPtr<IHost> m_host;
-    ComNatListenerPtr m_vboxListener;
+
+    ComNatListenerPtr m_NatListener;
+    ComNatListenerPtr m_VBoxListener;
+    ComNatListenerPtr m_VBoxClientListener;
     static INTNETSEG aXmitSeg[64];
 
@@ -399,4 +401,11 @@
             break;
         }
+
+        case VBoxEventType_OnVBoxSVCAvailabilityChanged:
+        {
+            LogRel(("VBoxSVC became unavailable, exiting.\n"));
+            shutdown();
+            break;
+        }
     }
     return hrc;
@@ -780,9 +789,11 @@
     AssertRCReturn(rc, rc);
 
-    ComEventTypeArray aNetEvents;
-    aNetEvents.push_back(VBoxEventType_OnNATNetworkPortForward);
-    aNetEvents.push_back(VBoxEventType_OnNATNetworkSetting);
-    rc = createNatListener(m_listener, virtualbox, this, aNetEvents);
-    AssertRCReturn(rc, rc);
+    {
+        ComEventTypeArray eventTypes;
+        eventTypes.push_back(VBoxEventType_OnNATNetworkPortForward);
+        eventTypes.push_back(VBoxEventType_OnNATNetworkSetting);
+        rc = createNatListener(m_NatListener, virtualbox, this, eventTypes);
+        AssertRCReturn(rc, rc);
+    }
 
 
@@ -792,9 +803,18 @@
     AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
 
-    ComEventTypeArray aVBoxEvents;
-    aVBoxEvents.push_back(VBoxEventType_OnHostNameResolutionConfigurationChange);
-    aVBoxEvents.push_back(VBoxEventType_OnNATNetworkStartStop);
-    rc = createNatListener(m_vboxListener, virtualbox, this, aVBoxEvents);
-    AssertRCReturn(rc, rc);
+    {
+        ComEventTypeArray eventTypes;
+        eventTypes.push_back(VBoxEventType_OnHostNameResolutionConfigurationChange);
+        eventTypes.push_back(VBoxEventType_OnNATNetworkStartStop);
+        rc = createNatListener(m_VBoxListener, virtualbox, this, eventTypes);
+        AssertRCReturn(rc, rc);
+    }
+
+    {
+        ComEventTypeArray eventTypes;
+        eventTypes.push_back(VBoxEventType_OnVBoxSVCAvailabilityChanged);
+        rc = createClientListener(m_VBoxClientListener, virtualboxClient, this, eventTypes);
+        AssertRCReturn(rc, rc);
+    }
 
     BOOL fIPv6Enabled = FALSE;
@@ -1045,4 +1065,8 @@
     m_vecPortForwardRule4.clear();
     m_vecPortForwardRule6.clear();
+
+    destroyNatListener(m_NatListener, virtualbox);
+    destroyNatListener(m_VBoxListener, virtualbox);
+    destroyClientListener(m_VBoxClientListener, virtualboxClient);
 
     return VINF_SUCCESS;
@@ -1370,8 +1394,7 @@
      {
          /* Create the window. */
-         hwnd = CreateWindowEx (WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST,
-                 g_WndClassName, g_WndClassName,
-                                                   WS_POPUPWINDOW,
-                                                  -200, -200, 100, 100, NULL, NULL, hInstance, NULL);
+         hwnd = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST,
+                               g_WndClassName, g_WndClassName, WS_POPUPWINDOW,
+                               -200, -200, 100, 100, NULL, NULL, hInstance, NULL);
 
          if (hwnd)
Index: /trunk/src/VBox/NetworkServices/NetLib/ComHostUtils.cpp
===================================================================
--- /trunk/src/VBox/NetworkServices/NetLib/ComHostUtils.cpp	(revision 54699)
+++ /trunk/src/VBox/NetworkServices/NetLib/ComHostUtils.cpp	(revision 54700)
@@ -214,2 +214,58 @@
     return VINF_SUCCESS;
 }
+
+int destroyNatListener(ComNatListenerPtr& listener, const ComVirtualBoxPtr& vboxptr)
+{
+    if (listener)
+    {
+        ComPtr<IEventSource> esVBox;
+        HRESULT hrc = vboxptr->COMGETTER(EventSource)(esVBox.asOutParam());
+        AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
+        if (!esVBox.isNull())
+        {
+            hrc = esVBox->UnregisterListener(listener);
+            AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
+        }
+        listener.setNull();
+    }
+    return VINF_SUCCESS;
+}
+
+int createClientListener(ComNatListenerPtr& listener, const ComVirtualBoxClientPtr& vboxclientptr,
+                         NATNetworkEventAdapter *adapter, /* const */ ComEventTypeArray& events)
+{
+    ComObjPtr<NATNetworkListenerImpl> obj;
+    HRESULT hrc = obj.createObject();
+    AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
+
+    hrc = obj->init(new NATNetworkListener(), adapter);
+    AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
+
+    ComPtr<IEventSource> esVBox;
+    hrc = vboxclientptr->COMGETTER(EventSource)(esVBox.asOutParam());
+    AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
+
+    listener = obj;
+
+    hrc = esVBox->RegisterListener(listener, ComSafeArrayAsInParam(events), true);
+    AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
+
+    return VINF_SUCCESS;
+}
+
+int destroyClientListener(ComNatListenerPtr& listener, const ComVirtualBoxClientPtr& vboxclientptr)
+{
+    if (listener)
+    {
+        ComPtr<IEventSource> esVBox;
+        HRESULT hrc = vboxclientptr->COMGETTER(EventSource)(esVBox.asOutParam());
+        AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
+        if (!esVBox.isNull())
+        {
+            hrc = esVBox->UnregisterListener(listener);
+            AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
+        }
+        listener.setNull();
+    }
+    return VINF_SUCCESS;
+}
Index: /trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp
===================================================================
--- /trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp	(revision 54699)
+++ /trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp	(revision 54700)
@@ -208,5 +208,8 @@
         AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
 
-        hrc = virtualbox.createLocalObject(CLSID_VirtualBox);
+        hrc = virtualboxClient.createInprocObject(CLSID_VirtualBoxClient);
+        AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
+
+        hrc = virtualboxClient->COMGETTER(VirtualBox)(virtualbox.asOutParam());
         AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
     }
Index: /trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.h
===================================================================
--- /trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.h	(revision 54699)
+++ /trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.h	(revision 54700)
@@ -132,4 +132,5 @@
     /* VirtualBox instance */
     ComPtr<IVirtualBox> virtualbox;
+    ComPtr<IVirtualBoxClient> virtualboxClient;
 
     private:
Index: /trunk/src/VBox/NetworkServices/NetLib/utils.h
===================================================================
--- /trunk/src/VBox/NetworkServices/NetLib/utils.h	(revision 54699)
+++ /trunk/src/VBox/NetworkServices/NetLib/utils.h	(revision 54700)
@@ -25,4 +25,5 @@
 
 typedef ComPtr<IVirtualBox> ComVirtualBoxPtr;
+typedef ComPtr<IVirtualBoxClient> ComVirtualBoxClientPtr;
 typedef ComPtr<IDHCPServer> ComDhcpServerPtr;
 typedef ComPtr<IHost> ComHostPtr;
@@ -131,3 +132,8 @@
 int createNatListener(ComNatListenerPtr& listener, const ComVirtualBoxPtr& vboxptr,
                       NATNetworkEventAdapter *adapter, /* const */ ComEventTypeArray& events);
+int destroyNatListener(ComNatListenerPtr& listener, const ComVirtualBoxPtr& vboxptr);
+int createClientListener(ComNatListenerPtr& listener, const ComVirtualBoxClientPtr& vboxclientptr,
+                         NATNetworkEventAdapter *adapter, /* const */ ComEventTypeArray& events);
+int destroyClientListener(ComNatListenerPtr& listener, const ComVirtualBoxClientPtr& vboxclientptr);
+
 #endif
