VirtualBox

Ignore:
Timestamp:
Mar 5, 2025 8:14:04 AM (2 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
167819
Message:

Windows driver installation/VBoxDrvInst: Implemented 'uninstall host' sub command to uninstall all VBox-related host drivers. bugref:10762

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/installation/VBoxDrvInst.cpp

    r107988 r108445  
    182182enum
    183183{
    184     VBOXDRVINST_UNINSTALL_OPT_INF_FILE = 900,
     184    VBOXDRVINST_UNINSTALL_OPT_HOST = 900,
     185    VBOXDRVINST_UNINSTALL_OPT_INF_FILE,
    185186    VBOXDRVINST_UNINSTALL_OPT_INF_SECTION,
    186187    VBOXDRVINST_UNINSTALL_OPT_MODEL,
    187188    VBOXDRVINST_UNINSTALL_OPT_PNPID,
     189    VBOXDRVINST_UNINSTALL_OPT_FORCE,
    188190    VBOXDRVINST_UNINSTALL_OPT_NOT_SILENT,
    189191    VBOXDRVINST_UNINSTALL_OPT_IGNORE_REBOOT
     
    195197static const RTGETOPTDEF g_aCmdUninstallOptions[] =
    196198{
     199    /* Sub commands. */
     200    { "host",            VBOXDRVINST_UNINSTALL_OPT_HOST,          RTGETOPT_REQ_NOTHING  },
     201    /* Parameters. */
    197202    { "--inf-file",      VBOXDRVINST_UNINSTALL_OPT_INF_FILE,      RTGETOPT_REQ_STRING  },
    198203    { "--inf-section",   VBOXDRVINST_UNINSTALL_OPT_INF_SECTION,   RTGETOPT_REQ_STRING  },
     
    201206    { "--pnpid" ,        VBOXDRVINST_UNINSTALL_OPT_PNPID,         RTGETOPT_REQ_STRING  },
    202207    { "--pnp-id",        VBOXDRVINST_UNINSTALL_OPT_PNPID,         RTGETOPT_REQ_STRING  },
     208    { "--force",         VBOXDRVINST_UNINSTALL_OPT_FORCE,         RTGETOPT_REQ_NOTHING },
    203209    { "--not-silent",    VBOXDRVINST_UNINSTALL_OPT_NOT_SILENT,    RTGETOPT_REQ_NOTHING },
    204210    { "--ignore-reboot", VBOXDRVINST_UNINSTALL_OPT_IGNORE_REBOOT, RTGETOPT_REQ_NOTHING }
     
    595601    switch (pOpt->iShort)
    596602    {
     603        case VBOXDRVINST_UNINSTALL_OPT_HOST:          return "Uninstalls all VirtualBox host drivers";
    597604        case VBOXDRVINST_UNINSTALL_OPT_INF_FILE:      return "Specifies the INF File to uninstall";
    598605        case VBOXDRVINST_UNINSTALL_OPT_INF_SECTION:   return "Specifies the INF section to uninstall";
    599606        case VBOXDRVINST_UNINSTALL_OPT_MODEL:         return "Specifies the driver model to uninstall";
    600607        case VBOXDRVINST_UNINSTALL_OPT_PNPID:         return "Specifies the PnP (device) ID to uninstall";
     608        case VBOXDRVINST_UNINSTALL_OPT_FORCE:         return "Forces uninstallation";
     609        case VBOXDRVINST_UNINSTALL_OPT_NOT_SILENT:    return "Runs uninstallation in non-silent mode";
    601610        case VBOXDRVINST_UNINSTALL_OPT_IGNORE_REBOOT: return "Ignores reboot requirements";
    602611        default:
     
    604613    }
    605614    return NULL;
     615}
     616
     617/**
     618 * Uninstalls all (see notes below) VirtualBox host-related drivers.
     619 *
     620 * @returns VBox status code.
     621 * @param   hDrvInst            Windows driver installer handle to use.
     622 * @param   fInstallFlags       [Un]Installation flags to use (of type VBOX_WIN_DRIVERINSTALL_F_XXX).
     623 */
     624static int vboxDrvInstCmdUninstallVBoxHost(VBOXWINDRVINST hDrvInst, uint32_t fInstallFlags)
     625{
     626    /** @todo Check for running VirtualBox processes first? */
     627
     628    int rc;
     629
     630#define UNINSTALL_DRIVER(a_Driver) \
     631    rc = VBoxWinDrvInstUninstall(hDrvInst, NULL /* pszInfFile */, a_Driver, NULL /* pszPnPId */, fInstallFlags); \
     632    if (   RT_FAILURE(rc) \
     633        && !(fInstallFlags & VBOX_WIN_DRIVERINSTALL_F_FORCE)) \
     634        return rc;
     635
     636#define CONTROL_SERVICE(a_Svc, a_Fn) \
     637    rc = VBoxWinDrvInstControlServiceEx(hDrvInst, a_Svc, a_Fn, VBOXWINDRVSVCFN_F_WAIT, RT_MS_30SEC); \
     638    if (RT_FAILURE(rc)) \
     639    { \
     640        if (   rc != VERR_NOT_FOUND /* Service is optional, thus not fatal if not found. */ \
     641            && !(fInstallFlags & VBOX_WIN_DRIVERINSTALL_F_FORCE)) \
     642            return rc; \
     643    }
     644
     645#define STOP_SERVICE(a_Svc) CONTROL_SERVICE(a_Svc, VBOXWINDRVSVCFN_STOP)
     646#define DELETE_SERVICE(a_Svc) CONTROL_SERVICE(a_Svc, VBOXWINDRVSVCFN_DELETE)
     647
     648    /* Stop VBoxSDS first. */
     649    STOP_SERVICE("VBoxSDS");
     650
     651    /*
     652     * Note! The order how to uninstall all drivers is important here,
     653     *       as drivers can (and will!) hold references to the VBoxSUP (VirtualBox support) driver.
     654     *       So do not change the order here unless you exactly know what you are doing.
     655     */
     656    static const char *s_aszDriverUninstallOrdered[] =
     657    {
     658        "VBoxNetAdp*", /* To catch also deprecated VBoxNetAdp5 drivers. */
     659        "VBoxNetLwf*",
     660        "VBoxUSB*"
     661    };
     662
     663    for (size_t i = 0; i < RT_ELEMENTS(s_aszDriverUninstallOrdered); i++)
     664        UNINSTALL_DRIVER(s_aszDriverUninstallOrdered[i]);
     665
     666    static const char *s_aszServicesToStopOrdered[] =
     667    {
     668        "VBoxNetAdp",
     669        "VBoxNetLwf",
     670        "VBoxUSBMon"
     671    };
     672
     673    for (size_t i = 0; i < RT_ELEMENTS(s_aszServicesToStopOrdered); i++)
     674        STOP_SERVICE(s_aszServicesToStopOrdered[i]);
     675
     676    /* Must come last. */
     677    UNINSTALL_DRIVER("VBoxSup*");
     678
     679    /* Delete all services (if not already done via driver uninstallation). */
     680    for (size_t i = 0; i < RT_ELEMENTS(s_aszServicesToStopOrdered); i++)
     681        DELETE_SERVICE(s_aszServicesToStopOrdered[i]);
     682
     683    /* Ditto. */
     684    DELETE_SERVICE("VBoxSup");
     685
     686#undef STOP_SERVICE
     687#undef UNINSTALL_DRIVER
     688
     689    return VINF_SUCCESS;
    606690}
    607691
     
    619703    char *pszInfSection = NULL;
    620704
    621     /* By default we want a silent uninstallation. */
     705    /* By default we want a silent uninstallation (but not forcing it). */
    622706    uint32_t fInstall = VBOX_WIN_DRIVERINSTALL_F_SILENT;
    623707
    624708    /* Whether to ignore reboot messages or not. This will also affect the returned exit code. */
    625709    bool fIgnoreReboot = false;
     710    /* Whether to (automatically) uninstall all related VBox host drivers or not. */
     711    bool fVBoxHost = false;
    626712
    627713    int rc = VINF_SUCCESS;
     
    645731                return vboxDrvInstShowUsage(g_pStdOut, &g_CmdUninstall);
    646732
     733            case VBOXDRVINST_UNINSTALL_OPT_HOST:
     734                fVBoxHost = true;
     735                break;
     736
    647737            case VBOXDRVINST_UNINSTALL_OPT_INF_FILE:
    648738                DUP_ARG_TO_STR(pszInfFile);
     
    659749            case VBOXDRVINST_UNINSTALL_OPT_PNPID:
    660750                DUP_ARG_TO_STR(pszPnpId);
     751                break;
     752
     753            case VBOXDRVINST_UNINSTALL_OPT_FORCE:
     754                fInstall |= VBOX_WIN_DRIVERINSTALL_F_FORCE;
    661755                break;
    662756
     
    685779    if (RT_SUCCESS(rc))
    686780    {
    687         rc = VBoxWinDrvInstUninstall(hWinDrvInst, pszInfFile, pszModel, pszPnpId, fInstall);
     781        if (fVBoxHost)
     782            rc = vboxDrvInstCmdUninstallVBoxHost(hWinDrvInst, fInstall);
     783        else
     784            rc = VBoxWinDrvInstUninstall(hWinDrvInst, pszInfFile, pszModel, pszPnpId, fInstall);
    688785        if (RT_SUCCESS(rc))
    689786        {
     
    878975    RTStrmPrintf(pStrm, "\t%s install   --inf-file C:\\Path\\To\\VBoxUSB.inf\n", pszProcName);
    879976    RTStrmPrintf(pStrm, "\t%s install   --debug-os-ver 6:0 --inf-file C:\\Path\\To\\VBoxGuest.inf\n", pszProcName);
     977    RTStrmPrintf(pStrm, "\t%s uninstall host\n", pszProcName);
    880978    RTStrmPrintf(pStrm, "\t%s uninstall --inf -file C:\\Path\\To\\VBoxUSB.inf --pnp-id \"USB\\VID_80EE&PID_CAFE\"\n", pszProcName);
    881979    RTStrmPrintf(pStrm, "\t%s uninstall --model \"VBoxUSB.AMD64\"\n", pszProcName);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette