Index: /trunk/include/VBox/ExtPack/ExtPack.h
===================================================================
--- /trunk/include/VBox/ExtPack/ExtPack.h	(revision 35183)
+++ /trunk/include/VBox/ExtPack/ExtPack.h	(revision 35184)
@@ -185,8 +185,16 @@
      * This is called in the context of the per-user service (VBoxSVC).
      *
+     * @returns VBox status code.
+     * @retval  VERR_EXTPACK_UNSUPPORTED_HOST_UNINSTALL if the extension pack
+     *          requires some different host version or a prerequisite is
+     *          missing from the host.  Automatic uninstall will be attempted.
+     *          Must set error info.
+     *
      * @param   pThis       Pointer to this structure.
      * @param   pVirtualBox The VirtualBox interface.
-     */
-    DECLCALLBACKMEMBER(void, pfnInstalled)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IVirtualBox) *pVirtualBox);
+     * @param   pErrInfo    Where to return extended error information.
+     */
+    DECLCALLBACKMEMBER(int, pfnInstalled)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IVirtualBox) *pVirtualBox,
+                                          PRTERRINFO pErrInfo);
 
     /**
@@ -198,4 +206,5 @@
      * @param   pThis       Pointer to this structure.
      * @param   pVirtualBox The VirtualBox interface.
+     *
      * @todo    This is currently called holding locks making pVirtualBox
      *          relatively unusable.
@@ -319,8 +328,7 @@
  *                          be valid and unchanged until the module is unloaded
  *                          (i.e. use some static const data for it).
- * @param   pszErr          Error message buffer for explaining any failure.
- * @param   cbErr           The size of the error message buffer.
- */
-typedef DECLCALLBACK(int) FNVBOXEXTPACKREGISTER(PCVBOXEXTPACKHLP pHlp, PCVBOXEXTPACKREG *ppReg, char *pszErr, size_t cbErr);
+ * @param   pErrInfo        Where to return extended error information.
+ */
+typedef DECLCALLBACK(int) FNVBOXEXTPACKREGISTER(PCVBOXEXTPACKHLP pHlp, PCVBOXEXTPACKREG *ppReg, PRTERRINFO pErrInfo);
 /** Pointer to a FNVBOXEXTPACKREGISTER. */
 typedef FNVBOXEXTPACKREGISTER *PFNVBOXEXTPACKREGISTER;
@@ -339,5 +347,5 @@
 #define VBOXEXTPACK_IS_VER_COMPAT(u32Provider, u32User) \
     (    VBOXEXTPACK_IS_MAJOR_VER_EQUAL(u32Provider, u32User) \
-      && RT_LOWORD(u32Provider) >= RT_LOWORD(u32User) )
+      && (int32_t)RT_LOWORD(u32Provider) >= (int32_t)RT_LOWORD(u32User) ) /* stupid casts to shut up gcc */
 
 /**
Index: /trunk/include/VBox/err.h
===================================================================
--- /trunk/include/VBox/err.h	(revision 35183)
+++ /trunk/include/VBox/err.h	(revision 35184)
@@ -1611,5 +1611,5 @@
  * @{
  */
-/** CPU hotplug events from VMMDev are not monitored by the guest */
+/** CPU hotplug events from VMMDev are not monitored by the guest. */
 #define VERR_CPU_HOTPLUG_NOT_MONITORED_BY_GUEST    (-4700)
 /** @} */
@@ -1625,11 +1625,11 @@
  * @{
  */
-/** LUN type is not supported */
+/** LUN type is not supported. */
 #define VERR_VSCSI_LUN_TYPE_NOT_SUPPORTED           (-4900)
-/** LUN is already/still attached to a device */
+/** LUN is already/still attached to a device. */
 #define VERR_VSCSI_LUN_ATTACHED_TO_DEVICE           (-4901)
-/** The specified LUN is invalid */
+/** The specified LUN is invalid. */
 #define VERR_VSCSI_LUN_INVALID                      (-4902)
-/** The LUN is not attached to the device */
+/** The LUN is not attached to the device. */
 #define VERR_VSCSI_LUN_NOT_ATTACHED                 (-4903)
 /** The LUN is still busy. */
@@ -1637,17 +1637,25 @@
 /** @} */
 
-/** @name VBox FAM error codes
- * @{
- */
-/** FAM failed to open a connection */
+/** @name VBox FAM Status Codes
+ * @{
+ */
+/** FAM failed to open a connection. */
 #define VERR_FAM_OPEN_FAILED                        (-5000)
-/** FAM failed to add a file to the list to be monitored */
+/** FAM failed to add a file to the list to be monitored. */
 #define VERR_FAM_MONITOR_FILE_FAILED                (-5001)
-/** FAM failed to add a directory to the list to be monitored */
+/** FAM failed to add a directory to the list to be monitored. */
 #define VERR_FAM_MONITOR_DIRECTORY_FAILED           (-5002)
-/** The connection to the FAM daemon was lost */
+/** The connection to the FAM daemon was lost. */
 #define VERR_FAM_CONNECTION_LOST                    (-5003)
 /** @} */
 
+/** @name VBox Extension Pack Status Codes
+ * @{
+ */
+/** The host is not supported. Uninstall the extension pack.
+ * Returned by the VBOXEXTPACKREG::pfnInstalled. */
+#define VERR_EXTPACK_UNSUPPORTED_HOST_UNINSTALL     (-5000)
+/** @} */
+
 /* SED-END */
 
Index: /trunk/src/VBox/Main/ExtPackManagerImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/ExtPackManagerImpl.cpp	(revision 35183)
+++ /trunk/src/VBox/Main/ExtPackManagerImpl.cpp	(revision 35184)
@@ -38,4 +38,5 @@
 #include <VBox/com/array.h>
 #include <VBox/com/ErrorInfo.h>
+#include <VBox/err.h>
 #include <VBox/log.h>
 #include <VBox/sup.h>
@@ -726,6 +727,7 @@
  * @param   a_pVirtualBox       The VirtualBox interface.
  * @param   a_pLock             The write lock held by the caller.
- */
-bool    ExtPack::callInstalledHook(IVirtualBox *a_pVirtualBox, AutoWriteLock *a_pLock)
+ * @param   pErrInfo            Where to return error information.
+ */
+bool    ExtPack::callInstalledHook(IVirtualBox *a_pVirtualBox, AutoWriteLock *a_pLock, PRTERRINFO pErrInfo)
 {
     if (   m != NULL
@@ -736,9 +738,10 @@
             ComPtr<ExtPack> ptrSelfRef = this;
             a_pLock->release();
-            m->pReg->pfnInstalled(m->pReg, a_pVirtualBox);
+            pErrInfo->rc = m->pReg->pfnInstalled(m->pReg, a_pVirtualBox, pErrInfo);
             a_pLock->acquire();
             return true;
         }
     }
+    pErrInfo->rc = VINF_SUCCESS;
     return false;
 }
@@ -1172,13 +1175,14 @@
     }
 
+    RTERRINFOSTATIC ErrInfo;
+    RTErrInfoInitStatic(&ErrInfo);
     if (fIsNative)
     {
-        char szError[8192];
-        vrc = RTLdrLoadEx(m->strMainModPath.c_str(), &m->hMainMod, 0 /*=fFlags*/, szError, sizeof(szError));
+        vrc = RTLdrLoadEx(m->strMainModPath.c_str(), &m->hMainMod, 0 /*fFlags*/, &ErrInfo.Core);
         if (RT_FAILURE(vrc))
         {
             m->hMainMod = NIL_RTLDRMOD;
             m->strWhyUnusable.printf(tr("Failed to locate load the main module ('%s'): %Rrc - %s"),
-                                           m->strMainModPath.c_str(), vrc, szError);
+                                     m->strMainModPath.c_str(), vrc, ErrInfo.Core.pszMsg);
             return;
         }
@@ -1197,8 +1201,8 @@
     if (RT_SUCCESS(vrc))
     {
-        RT_ZERO(szErr);
-        vrc = pfnRegistration(&m->Hlp, &m->pReg, szErr, sizeof(szErr) - 16);
+        RTErrInfoClear(&ErrInfo.Core);
+        vrc = pfnRegistration(&m->Hlp, &m->pReg, &ErrInfo.Core);
         if (   RT_SUCCESS(vrc)
-            && szErr[0] == '\0'
+            && !RTErrInfoIsSet(&ErrInfo.Core)
             && VALID_PTR(m->pReg))
         {
@@ -1233,9 +1237,6 @@
         }
         else
-        {
-            szErr[sizeof(szErr) - 1] = '\0';
-            m->strWhyUnusable.printf(tr("%s returned %Rrc, pReg=%p szErr='%s'"),
-                                     VBOX_EXTPACK_MAIN_MOD_ENTRY_POINT, vrc, m->pReg, szErr);
-        }
+            m->strWhyUnusable.printf(tr("%s returned %Rrc, pReg=%p ErrInfo='%s'"),
+                                     VBOX_EXTPACK_MAIN_MOD_ENTRY_POINT, vrc, m->pReg, ErrInfo.Core.pszMsg);
         m->pReg = NULL;
     }
@@ -2488,6 +2489,26 @@
                 if (SUCCEEDED(hrc))
                 {
-                    LogRel(("ExtPackManager: Successfully installed extension pack '%s'.\n", pStrName->c_str()));
-                    pExtPack->callInstalledHook(m->pVirtualBox, &autoLock);
+                    RTERRINFOSTATIC ErrInfo;
+                    RTErrInfoInitStatic(&ErrInfo);
+                    pExtPack->callInstalledHook(m->pVirtualBox, &autoLock, &ErrInfo.Core);
+                    if (RT_SUCCESS(ErrInfo.Core.rc))
+                        LogRel(("ExtPackManager: Successfully installed extension pack '%s'.\n", pStrName->c_str()));
+                    else
+                    {
+                        LogRel(("ExtPackManager: Installated hook for '%s' failed: %Rrc - %s\n",
+                                pStrName->c_str(), ErrInfo.Core.rc, ErrInfo.Core.pszMsg));
+
+                        /*
+                         * Uninstall the extpack if the error indicates that.
+                         */
+                        if (ErrInfo.Core.rc == VERR_EXTPACK_UNSUPPORTED_HOST_UNINSTALL)
+                            runSetUidToRootHelper("uninstall",
+                                                  "--base-dir", m->strBaseDir.c_str(),
+                                                  "--name",     pStrName->c_str(),
+                                                  "--forced",
+                                                  (const char *)NULL);
+                        hrc = setError(E_FAIL, tr("The installation hook failed: %Rrc - %s"),
+                                       ErrInfo.Core.rc, ErrInfo.Core.pszMsg);
+                    }
                 }
             }
Index: /trunk/src/VBox/Main/include/ExtPackManagerImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/ExtPackManagerImpl.h	(revision 35183)
+++ /trunk/src/VBox/Main/include/ExtPackManagerImpl.h	(revision 35184)
@@ -139,5 +139,5 @@
     /** @name Internal interfaces used by ExtPackManager.
      * @{ */
-    bool        callInstalledHook(IVirtualBox *a_pVirtualBox, AutoWriteLock *a_pLock);
+    bool        callInstalledHook(IVirtualBox *a_pVirtualBox, AutoWriteLock *a_pLock, PRTERRINFO pErrInfo);
     HRESULT     callUninstallHookAndClose(IVirtualBox *a_pVirtualBox, bool a_fForcedRemoval);
     bool        callVirtualBoxReadyHook(IVirtualBox *a_pVirtualBox, AutoWriteLock *a_pLock);
