Index: /trunk/src/VBox/Main/src-server/win/svcmain.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/win/svcmain.cpp	(revision 69802)
+++ /trunk/src/VBox/Main/src-server/win/svcmain.cpp	(revision 69803)
@@ -79,6 +79,12 @@
 HINSTANCE   g_hInstance   = NULL;
 #ifdef VBOX_WITH_SDS
-/** This is set if we're connected to SDS and should discount a server lock
- * that it is holding when deciding whether we're idle or not. */
+/** This is set if we're connected to SDS.
+ *
+ * It means that we should discount a server lock that it is holding when
+ * deciding whether we're idle or not.
+ *
+ * Also, when set we deregister with SDS during class factory destruction.  We
+ * exploit this to prevent attempts to deregister during or after COM shutdown.
+ */
 bool        g_fRegisteredWithVBoxSDS = false;
 #endif
@@ -220,6 +226,8 @@
         }
 
-        /** @todo Need to check if this is okay wrt COM termination. */
-        i_deregisterWithSds();
+        /* We usually get here during g_pModule->Term() via CoRevokeClassObjec, so COM
+           probably working well enough to talk to SDS when we get here. */
+        if (g_fRegisteredWithVBoxSDS)
+            i_deregisterWithSds();
     }
 
@@ -323,5 +331,5 @@
         if (SUCCEEDED(hrc))
         {
-            g_fRegisteredWithVBoxSDS = true;
+            g_fRegisteredWithVBoxSDS = !*ppOtherVirtualBox;
             return hrc;
         }
@@ -901,4 +909,7 @@
     g_pModule->Term();
 
+#ifdef VBOX_WITH_SDS
+    g_fRegisteredWithVBoxSDS = false; /* Don't trust COM LPC to work right from now on.  */
+#endif
     com::Shutdown();
 
