Skip to content

Commit f49b24b

Browse files
author
Ben Hillis
committed
use MSIRMSHUTDOWN = 1 instead of custom action
1 parent 4ababc2 commit f49b24b

4 files changed

Lines changed: 2 additions & 59 deletions

File tree

msipackage/package.wix.in

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@
241241

242242
<File Id="wsldevicehost.dll" Source="${WSL_DEVICE_HOST_SOURCE_DIR}/bin/${TARGET_PLATFORM}/wsldevicehost.dll" />
243243

244-
245244
<!-- WSLC COM app - activated through WSLService -->
246245
<RegistryKey Root="HKCR" Key="AppID\{E9B79997-57E3-4201-AECC-6A464E530DD2}">
247246
<!-- O:BAG:BAD:(A;;CCDCSW;;;AU)(A;;CCDCSW;;;PS)(A;;CCDCSW;;;SY) -->
@@ -524,14 +523,6 @@
524523
Execute="deferred"
525524
/>
526525

527-
<CustomAction Id="StopDeviceHostSurrogate"
528-
Impersonate="no"
529-
BinaryRef="wslinstall.dll"
530-
DllEntry="StopDeviceHostSurrogate"
531-
Return="check"
532-
Execute="deferred"
533-
/>
534-
535526
<CustomAction Id="DeprovisionMsix"
536527
Impersonate="no"
537528
BinaryRef="wslinstall.dll"
@@ -620,11 +611,6 @@
620611
<InstallExecuteSequence>
621612
<Custom Action="ValidateInstall" After="InstallInitialize" Condition="(not INSTALLED) and (not SKIPVALIDATION = 1)" />
622613

623-
<!-- Terminate the dllhost.exe surrogate hosting wsldevicehost.dll so the DLL can be overwritten when installing files.
624-
Must run after StopService (which stops WSLService) but before InstallFiles.
625-
Conditioned on '(not UPGRADINGPRODUCTCODE)' so it does not run in the old product's removal sequence during major upgrades. -->
626-
<Custom Action="StopDeviceHostSurrogate" Before="InstallFiles" Condition='(not UPGRADINGPRODUCTCODE)' />
627-
628614
<!-- Must run before InstallServices or else we'll fail if wslservice already exists.
629615
Covers cases where:
630616
- The MSI package is installed for the first time and the old MSIX needs to be removed
@@ -690,7 +676,7 @@
690676
<!-- Force all applications to exit during upgrade.
691677
See: https://learn.microsoft.com/en-us/windows/win32/msi/msirmshutdown
692678
-->
693-
<Property Id="MSIRMSHUTDOWN" Value="0" Secure="yes" />
679+
<Property Id="MSIRMSHUTDOWN" Value="1" Secure="yes" />
694680
</Package>
695681
</Wix>
696682

src/windows/wslinstall/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ target_link_libraries(wslinstall
1414
common
1515
legacy_stdio_definitions
1616
Crypt32.lib
17-
sfc.lib
18-
rstrtmgr.lib)
17+
sfc.lib)

src/windows/wslinstall/DllMain.cpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ Module Name:
1919
#include <winrt/Windows.Foundation.Collections.h>
2020
#include <winrt/windows.management.deployment.h>
2121
#include <Sfc.h>
22-
#include <RestartManager.h>
2322
#include "defs.h"
2423

2524
using unique_msi_handle = wil::unique_any<MSIHANDLE, decltype(MsiCloseHandle), &MsiCloseHandle>;
@@ -801,46 +800,6 @@ extern "C" UINT __stdcall WslFinalizeInstallation(MSIHANDLE install)
801800
return NOERROR;
802801
}
803802

804-
extern "C" UINT __stdcall StopDeviceHostSurrogate(MSIHANDLE install)
805-
{
806-
// Use the Restart Manager to find and shut down any process that has wsldevicehost.dll locked.
807-
// This must run before InstallFiles to ensure the DLL can be overwritten when installing files.
808-
809-
try
810-
{
811-
WSL_INSTALL_LOG("StopDeviceHostSurrogate");
812-
813-
const auto installRoot = wsl::windows::common::wslutil::GetMsiPackagePath();
814-
if (!installRoot.has_value())
815-
{
816-
return NOERROR;
817-
}
818-
819-
const auto dllPath = installRoot.value() + L"wsldevicehost.dll";
820-
821-
DWORD session{};
822-
WCHAR sessionKey[CCH_RM_SESSION_KEY + 1]{};
823-
THROW_IF_WIN32_ERROR(RmStartSession(&session, 0, sessionKey));
824-
auto endSession = wil::scope_exit([&] { RmEndSession(session); });
825-
826-
LPCWSTR file = dllPath.c_str();
827-
THROW_IF_WIN32_ERROR(RmRegisterResources(session, 1, &file, 0, nullptr, 0, nullptr));
828-
829-
// First attempt a graceful shutdown of processes using wsldevicehost.dll.
830-
DWORD rmError = RmShutdown(session, 0, nullptr);
831-
if (rmError != ERROR_SUCCESS)
832-
{
833-
// If graceful shutdown failed, do a forced shutdown.
834-
WSL_INSTALL_LOG("StopDeviceHostSurrogate: graceful shutdown failed, attempting forced shutdown.");
835-
THROW_IF_WIN32_ERROR(RmShutdown(session, RmForceShutdown, nullptr));
836-
}
837-
}
838-
CATCH_LOG();
839-
840-
// Always succeed — failure to stop the surrogate is not fatal.
841-
return NOERROR;
842-
}
843-
844803
extern "C" UINT __stdcall WslValidateInstallation(MSIHANDLE install)
845804
try
846805
{

src/windows/wslinstall/wslinstall.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ EXPORTS
44
CleanExplorerState
55
CleanMsixState
66
DeprovisionMsix
7-
StopDeviceHostSurrogate
87
WslValidateInstallation
98
WslFinalizeInstallation
109
InstallMsix

0 commit comments

Comments
 (0)