VirtualBox

Changeset 93242 in vbox for trunk/src/VBox/Installer/win


Ignore:
Timestamp:
Jan 14, 2022 10:58:11 PM (3 years ago)
Author:
vboxsync
Message:

Installer/win: Added custom action for removing old VBoxDrv service. bugref:10162

Location:
trunk/src/VBox/Installer/win
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Installer/win/InstallHelper/VBoxInstallHelper.cpp

    r93115 r93242  
    18611861}
    18621862
     1863
     1864/**
     1865 * This is used to remove the old VBoxDrv service before installation.
     1866 *
     1867 * The current service name is VBoxSup but the INF file won't remove the old
     1868 * one, so we do it manually to try prevent trouble as the device nodes are the
     1869 * same and we would fail starting VBoxSup.sys if VBoxDrv.sys is still loading.
     1870 *
     1871 * Status code is ignored for now as a reboot should fix most potential trouble
     1872 * here (and I don't want to break stuff too badly).
     1873 *
     1874 * @sa @bugref{10162}
     1875 */
     1876UINT __stdcall UninstallVBoxDrv(MSIHANDLE hModule)
     1877{
     1878    /*
     1879     * Try open the service.
     1880     */
     1881    SC_HANDLE hSMgr = OpenSCManager(NULL, NULL, SERVICE_CHANGE_CONFIG | SERVICE_STOP | SERVICE_QUERY_STATUS);
     1882    if (hSMgr)
     1883    {
     1884        SC_HANDLE hService = OpenServiceW(hSMgr, L"VBoxDrv", DELETE | SERVICE_STOP | SERVICE_QUERY_STATUS);
     1885        if (hService)
     1886        {
     1887            /*
     1888             * Try stop it before we delete it.
     1889             */
     1890            SERVICE_STATUS Status = { 0, 0, 0, 0, 0, 0, 0 };
     1891            QueryServiceStatus(hService, &Status);
     1892            if (Status.dwCurrentState == SERVICE_STOPPED)
     1893                logStringF(hModule, "VBoxDrv: The service old service was already stopped");
     1894            else
     1895            {
     1896                logStringF(hModule, "VBoxDrv: Stopping the service (state %u)", Status.dwCurrentState);
     1897                if (ControlService(hService, SERVICE_CONTROL_STOP, &Status))
     1898                {
     1899                    /* waiting for it to stop: */
     1900                    int iWait = 100;
     1901                    while (Status.dwCurrentState == SERVICE_STOP_PENDING && iWait-- > 0)
     1902                    {
     1903                        Sleep(100);
     1904                        QueryServiceStatus(hService, &Status);
     1905                    }
     1906
     1907                    if (Status.dwCurrentState == SERVICE_STOPPED)
     1908                        logStringF(hModule, "VBoxDrv: Stopped service");
     1909                    else
     1910                        logStringF(hModule, "VBoxDrv: Failed to stop the service, status: %u", Status.dwCurrentState);
     1911                }
     1912                else
     1913                {
     1914                    DWORD const dwErr = GetLastError();
     1915                    if (   Status.dwCurrentState == SERVICE_STOP_PENDING
     1916                        && dwErr == ERROR_SERVICE_CANNOT_ACCEPT_CTRL)
     1917                        logStringF(hModule, "VBoxDrv: Failed to stop the service: stop pending, not accepting control messages");
     1918                    else
     1919                        logStringF(hModule, "VBoxDrv: Failed to stop the service: dwErr=%u status=%u", dwErr, Status.dwCurrentState);
     1920                }
     1921            }
     1922
     1923            /*
     1924             * Delete the service, or at least mark it for deletion.
     1925             */
     1926            if (DeleteService(hService))
     1927                logStringF(hModule, "VBoxDrv: Successfully delete service");
     1928            else
     1929                logStringF(hModule, "VBoxDrv: Failed to delete the service: %u", GetLastError());
     1930
     1931            CloseServiceHandle(hService);
     1932        }
     1933        else
     1934        {
     1935            DWORD const dwErr = GetLastError();
     1936            if (dwErr == ERROR_SERVICE_DOES_NOT_EXIST)
     1937                logStringF(hModule, "VBoxDrv: Nothing to do, the old service does not exist");
     1938            else
     1939                logStringF(hModule, "VBoxDrv: Failed to open the service: %u", dwErr);
     1940        }
     1941
     1942        CloseServiceHandle(hSMgr);
     1943    }
     1944    else
     1945        logStringF(hModule, "VBoxDrv: Failed to open service manager (%u).", GetLastError());
     1946
     1947    return ERROR_SUCCESS;
     1948}
     1949
     1950
  • trunk/src/VBox/Installer/win/InstallHelper/VBoxInstallHelper.def

    r93115 r93242  
    3131    UninstallNetLwf
    3232    UninstallTAPInstances
     33    UninstallVBoxDrv
    3334    CreateHostOnlyInterface
    3435    StopHostOnlyInterfaces
  • trunk/src/VBox/Installer/win/VirtualBox.wxs

    r93239 r93242  
    202202                  DllEntry="UninstallTAPInstances" Execute="deferred" Return="check" Impersonate="no"/>
    203203
     204    <CustomAction Id="ca_UninstallVBoxDrv" BinaryKey="VBoxInstallHelper"
     205                  DllEntry="UninstallVBoxDrv" Execute="deferred" Return="ignore" Impersonate="no"/>
     206
    204207    <Property Id="VBOXDEPENDENCY" Secure="yes">
    205208        <DirectorySearch Id="VBoxInstallDir" Path="[EXISTINGINSTALLDIR]">
     
    624627        <Custom Action="ca_UninstallTAPInstances" Before="InstallFiles" >1</Custom>
    625628
     629        <!-- Check + uninstall old VBoxDrv service - it was renamed to VBoxSup.  -->
     630        <Custom Action="ca_UninstallVBoxDrv" Before="InstallFiles" >1</Custom>
     631
    626632        <Custom Action="ca_InstallBrandingArgs" Before="ca_InstallBranding" ><![CDATA[NOT REMOVE]]></Custom>
    627633        <Custom Action="ca_InstallBranding" Before="InstallFinalize" ><![CDATA[NOT REMOVE]]></Custom>
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