Changeset 108445 in vbox
- Timestamp:
- Mar 5, 2025 8:14:04 AM (2 months ago)
- svn:sync-xref-src-repo-rev:
- 167819
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/installation/VBoxDrvInst.cpp
r107988 r108445 182 182 enum 183 183 { 184 VBOXDRVINST_UNINSTALL_OPT_INF_FILE = 900, 184 VBOXDRVINST_UNINSTALL_OPT_HOST = 900, 185 VBOXDRVINST_UNINSTALL_OPT_INF_FILE, 185 186 VBOXDRVINST_UNINSTALL_OPT_INF_SECTION, 186 187 VBOXDRVINST_UNINSTALL_OPT_MODEL, 187 188 VBOXDRVINST_UNINSTALL_OPT_PNPID, 189 VBOXDRVINST_UNINSTALL_OPT_FORCE, 188 190 VBOXDRVINST_UNINSTALL_OPT_NOT_SILENT, 189 191 VBOXDRVINST_UNINSTALL_OPT_IGNORE_REBOOT … … 195 197 static const RTGETOPTDEF g_aCmdUninstallOptions[] = 196 198 { 199 /* Sub commands. */ 200 { "host", VBOXDRVINST_UNINSTALL_OPT_HOST, RTGETOPT_REQ_NOTHING }, 201 /* Parameters. */ 197 202 { "--inf-file", VBOXDRVINST_UNINSTALL_OPT_INF_FILE, RTGETOPT_REQ_STRING }, 198 203 { "--inf-section", VBOXDRVINST_UNINSTALL_OPT_INF_SECTION, RTGETOPT_REQ_STRING }, … … 201 206 { "--pnpid" , VBOXDRVINST_UNINSTALL_OPT_PNPID, RTGETOPT_REQ_STRING }, 202 207 { "--pnp-id", VBOXDRVINST_UNINSTALL_OPT_PNPID, RTGETOPT_REQ_STRING }, 208 { "--force", VBOXDRVINST_UNINSTALL_OPT_FORCE, RTGETOPT_REQ_NOTHING }, 203 209 { "--not-silent", VBOXDRVINST_UNINSTALL_OPT_NOT_SILENT, RTGETOPT_REQ_NOTHING }, 204 210 { "--ignore-reboot", VBOXDRVINST_UNINSTALL_OPT_IGNORE_REBOOT, RTGETOPT_REQ_NOTHING } … … 595 601 switch (pOpt->iShort) 596 602 { 603 case VBOXDRVINST_UNINSTALL_OPT_HOST: return "Uninstalls all VirtualBox host drivers"; 597 604 case VBOXDRVINST_UNINSTALL_OPT_INF_FILE: return "Specifies the INF File to uninstall"; 598 605 case VBOXDRVINST_UNINSTALL_OPT_INF_SECTION: return "Specifies the INF section to uninstall"; 599 606 case VBOXDRVINST_UNINSTALL_OPT_MODEL: return "Specifies the driver model to uninstall"; 600 607 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"; 601 610 case VBOXDRVINST_UNINSTALL_OPT_IGNORE_REBOOT: return "Ignores reboot requirements"; 602 611 default: … … 604 613 } 605 614 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 */ 624 static 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; 606 690 } 607 691 … … 619 703 char *pszInfSection = NULL; 620 704 621 /* By default we want a silent uninstallation . */705 /* By default we want a silent uninstallation (but not forcing it). */ 622 706 uint32_t fInstall = VBOX_WIN_DRIVERINSTALL_F_SILENT; 623 707 624 708 /* Whether to ignore reboot messages or not. This will also affect the returned exit code. */ 625 709 bool fIgnoreReboot = false; 710 /* Whether to (automatically) uninstall all related VBox host drivers or not. */ 711 bool fVBoxHost = false; 626 712 627 713 int rc = VINF_SUCCESS; … … 645 731 return vboxDrvInstShowUsage(g_pStdOut, &g_CmdUninstall); 646 732 733 case VBOXDRVINST_UNINSTALL_OPT_HOST: 734 fVBoxHost = true; 735 break; 736 647 737 case VBOXDRVINST_UNINSTALL_OPT_INF_FILE: 648 738 DUP_ARG_TO_STR(pszInfFile); … … 659 749 case VBOXDRVINST_UNINSTALL_OPT_PNPID: 660 750 DUP_ARG_TO_STR(pszPnpId); 751 break; 752 753 case VBOXDRVINST_UNINSTALL_OPT_FORCE: 754 fInstall |= VBOX_WIN_DRIVERINSTALL_F_FORCE; 661 755 break; 662 756 … … 685 779 if (RT_SUCCESS(rc)) 686 780 { 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); 688 785 if (RT_SUCCESS(rc)) 689 786 { … … 878 975 RTStrmPrintf(pStrm, "\t%s install --inf-file C:\\Path\\To\\VBoxUSB.inf\n", pszProcName); 879 976 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); 880 978 RTStrmPrintf(pStrm, "\t%s uninstall --inf -file C:\\Path\\To\\VBoxUSB.inf --pnp-id \"USB\\VID_80EE&PID_CAFE\"\n", pszProcName); 881 979 RTStrmPrintf(pStrm, "\t%s uninstall --model \"VBoxUSB.AMD64\"\n", pszProcName);
Note:
See TracChangeset
for help on using the changeset viewer.