VirtualBox

Changeset 106484 in vbox for trunk/src/VBox/GuestHost


Ignore:
Timestamp:
Oct 18, 2024 3:35:06 PM (3 months ago)
Author:
vboxsync
Message:

Windows driver installation: Try a bit harder running the [un]installation sections by probing various combinations. bugref:10762

File:
1 edited

Legend:

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

    r106397 r106484  
    746746 *
    747747 * @returns VBox status code.
     748 * @retval  VERR_NOT_FOUND if the given section has not been found.
    748749 * @param   pCtx                Windows driver installer context.
    749750 * @param   pwszInfFile         INF file to execute.
     
    751752 *                              Can have a platform decoration (e.g. "Foobar.NTx86").
    752753 */
    753 static int vboxWinDrvUninstallInfSectionEx(PVBOXWINDRVINSTINTERNAL pCtx, PRTUTF16 pwszInfFile, PRTUTF16 pwszSection)
     754static int vboxWinDrvUninstallInfSectionEx(PVBOXWINDRVINSTINTERNAL pCtx, PCRTUTF16 pwszInfFile, PCRTUTF16 pwszSection)
    754755{
    755756    AssertPtrReturn(pwszInfFile, VERR_INVALID_POINTER);
     
    762763    if (RT_FAILURE(rc))
    763764    {
    764         vboxWinDrvInstLogError(pCtx, "Unable to open INF file: %Rrc\n", rc);
     765        if (rc == VERR_FILE_NOT_FOUND)
     766            vboxWinDrvInstLogVerbose(pCtx, 1, "INF file not found anymore, skipping");
     767        else
     768            vboxWinDrvInstLogError(pCtx, "Unable to open INF file: %Rrc", rc);
    765769        return rc;
    766770    }
     
    783787            DWORD const dwErr = GetLastError();
    784788            if (dwErr == ERROR_SECTION_NOT_FOUND)
    785                 vboxWinDrvInstLogVerbose(pCtx, 1, "INF section \"%ls\" not found, skpping", wszSection);
     789            {
     790                vboxWinDrvInstLogVerbose(pCtx, 1, "INF section \"%ls\" not found", wszSection);
     791                rc = VERR_NOT_FOUND;
     792            }
    786793            else
    787794            {
     
    819826 *
    820827 * @returns VBox status code.
     828 * @retval  VERR_NOT_FOUND if the given section has not been found.
    821829 * @param   pCtx                Windows driver installer context.
    822830 * @param   pwszInfFile         INF file to execute.
     
    882890            DWORD const dwErr = GetLastError();
    883891            if (dwErr == ERROR_SECTION_NOT_FOUND)
     892            {
    884893                vboxWinDrvInstLogVerbose(pCtx, 1, "INF section \"%ls\" not found, skipping", wszSection);
     894                rc = VERR_NOT_FOUND;
     895            }
    885896            else if (dwErr == ERROR_SERVICE_MARKED_FOR_DELETE)
    886897                vboxWinDrvInstLogWarn(pCtx, "Service in INF section \"%ls\" already marked for deletion, skipping", wszSection);
     
    927938 * Installs a section of a given INF file.
    928939 *
    929  * Only supported for the VBOXWINDRVINSTMODE_INSTALL_EXECINF + VBOXWINDRVINSTMODE_UNINSTALL_EXECINF modes.
    930  *
    931  * @returns VBox status code.
     940 * Only supported for the VBOXWINDRVINSTMODE_INSTALL_INFSECTION + VBOXWINDRVINSTMODE_UNINSTALL_INFSECTION modes.
     941 *
     942 * @returns VBox status code.
     943 * @retval  VERR_NOT_FOUND if the given section has not been found.
    932944 * @param   pCtx                Windows driver installer context.
    933945 * @param   pParms              Windows driver installation parameters to use.
     
    939951
    940952    return vboxWinDrvInstallInfSectionEx(pCtx, pParms->pwszInfFile, pParms->u.ExecuteInf.pwszSection);
     953}
     954
     955/**
     956 * Tries probing a list of well-known sections for installation and will install the first one found.
     957 *
     958 * @returns VBox status code.
     959 * @param   pCtx                Windows driver installer context.
     960 * @param   pParms              Windows driver installation parameters to use.
     961 */
     962static int vboxWinDrvInstallTryInfSections(PVBOXWINDRVINSTINTERNAL pCtx, PVBOXWINDRVINSTPARMS pParms)
     963{
     964    /* Sorted by most likely-ness. */
     965    PRTUTF16 apwszTryInstallSections[] =
     966    {
     967        /* The more specific (using decorations), the better. Try these first. */
     968        pParms->u.UnInstall.pwszModel,
     969        /* Applies to primitive drivers. */
     970        L"DefaultInstall" VBOXWINDRVINF_DOT_NT_NATIVE_ARCH_STR,
     971        L"DefaultInstall"
     972    };
     973
     974    int rc = VINF_SUCCESS; /* Shut up MSVC. */
     975
     976    for (int i = 0; i < RT_ELEMENTS(apwszTryInstallSections); i++)
     977    {
     978        PRTUTF16 const pwszSection = apwszTryInstallSections[i];
     979
     980        rc = vboxWinDrvInstallInfSectionEx(pCtx, pParms->pwszInfFile, pwszSection);
     981        if (RT_SUCCESS(rc))
     982            break;
     983
     984        if (rc != VERR_NOT_FOUND)
     985            vboxWinDrvInstLogError(pCtx, "Installing INF section failed with %Rrc", rc);
     986    }
     987
     988    if (rc == VERR_NOT_FOUND)
     989    {
     990        vboxWinDrvInstLogWarn(pCtx, "No matching installation section found -- buggy driver?");
     991        rc = VINF_SUCCESS;
     992    }
     993
     994    return rc;
    941995}
    942996
     
    9801034                    rc = vboxWinDrvParmsDetermine(pCtx, pParms, true /* fForce */);
    9811035                    if (RT_SUCCESS(rc))
    982                     {
    983                         if (pParms->u.UnInstall.pwszModel)
    984                             rc = vboxWinDrvInstallInfSectionEx(pCtx, pCtx->Parms.pwszInfFile,
    985                                                                pParms->u.UnInstall.pwszModel);
    986                     }
     1036                        /* rc ignored, keep going */ vboxWinDrvInstallTryInfSections(pCtx, pParms);
    9871037                }
    9881038                else
     
    12211271
    12221272/**
     1273 * Tries probing a list of well-known sections for uninstallation and will uninstall the first one found.
     1274 *
     1275 * @returns VBox status code.
     1276 * @param   pCtx                Windows driver installer context.
     1277 * @param   pParms              Windows driver uninstallation parameters to use.
     1278 * @param   pwszInfPathAbs      Absolute path of INF file to use for uninstallation.
     1279 */
     1280static int vboxWinDrvUninstallTryInfSections(PVBOXWINDRVINSTINTERNAL pCtx, PVBOXWINDRVINSTPARMS pParms, PCRTUTF16 pwszInfPathAbs)
     1281{
     1282    /* Sorted by most likely-ness. */
     1283    PRTUTF16 s_apwszTryInstallSections[] =
     1284    {
     1285        /* The more specific (using decorations), the better. Try these first. */
     1286        pParms->u.UnInstall.pwszModel,
     1287        /* Applies to primitive drivers. */
     1288        L"DefaultUninstall" VBOXWINDRVINF_DOT_NT_NATIVE_ARCH_STR,
     1289        L"DefaultUninstall"
     1290    };
     1291
     1292    int rc = VINF_SUCCESS; /* Shut up MSVC. */
     1293
     1294    for (int i = 0; i < RT_ELEMENTS(s_apwszTryInstallSections); i++)
     1295    {
     1296        PRTUTF16 const pwszSection = s_apwszTryInstallSections[i];
     1297
     1298        rc = vboxWinDrvUninstallInfSectionEx(pCtx, pwszInfPathAbs, pwszSection);
     1299        if (RT_SUCCESS(rc))
     1300            break;
     1301
     1302        if (rc == VERR_FILE_NOT_FOUND) /* File gone already. */
     1303        {
     1304            rc = VINF_SUCCESS;
     1305            break;
     1306        }
     1307
     1308        if (rc != VERR_FILE_NOT_FOUND)
     1309            vboxWinDrvInstLogError(pCtx, "Uninstalling INF section failed with %Rrc", rc);
     1310    }
     1311
     1312    if (rc == VERR_NOT_FOUND)
     1313    {
     1314        vboxWinDrvInstLogWarn(pCtx, "No matching uninstallation section found -- buggy driver?");
     1315        rc = VINF_SUCCESS;
     1316    }
     1317
     1318    return rc;
     1319}
     1320
     1321/**
    12231322 * Removes OEM INF files from the driver store.
    12241323 *
     
    12521351        vboxWinDrvInstLogInfo(pCtx, "Uninstalling OEM INF \"%ls\" ...", wszInfPathAbs);
    12531352
    1254         int rc2 = vboxWinDrvUninstallInfSectionEx(pCtx, wszInfPathAbs,
    1255                                                   L"DefaultUninstall" VBOXWINDRVINF_DOT_NT_NATIVE_ARCH_STR);
    1256         if (RT_FAILURE(rc2))
    1257             vboxWinDrvInstLogError(pCtx, "Uninstalling INF section failed with %Rrc", rc2);
    1258 
    12591353        /*
    12601354         * Remove the driver from the driver store.
     
    12861380        else
    12871381            rc = vboxWinDrvInstLogLastError(pCtx, "Uninstalling OEM INF \"%ls\" failed", wszInfPathAbs);
     1382
     1383        /* If anything failed above, try removing stuff ourselves as good as we can. */
     1384        /* rc ignored, keep going */ vboxWinDrvUninstallTryInfSections(pCtx, pParms, wszInfPathAbs);
    12881385    }
    12891386
Note: See TracChangeset for help on using the changeset viewer.

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