Repository navigation
Conversation
…ppContainer profiles - Fixes freestylefly#39 and freestylefly#38 - Windows 11 (24H2/25H2, Build 26100/26200) enables PROCESS_MITIGATION_REDIRECTION_TRUST_POLICY on AppXSvc (SYSTEM), which blocks traversing or deleting user-created filesystem junctions inside %LOCALAPPDATA%\Packages\<PackageFamilyName>, returning ERROR_UNTRUSTED_MOUNT_POINT (0x800701C0) when DeleteAppContainerProfile is called. - In-place updates no longer needlessly call Remove-AppxPackage before Add-AppxPackage, avoiding leaving residual unlinked AppContainer state and instead using -ForceApplicationShutdown -ForceUpdateFromAnyVersion directly. - Clear orphaned AppContainer profiles, junctions, and directories via Userenv DeleteAppContainerProfile and safe directory unbinding before registering if the package is not currently registered. - Add retry mechanism to Add-AppxPackage that purges orphaned profiles and retries upon failure. - Ensure Unregister-ShareTarget.ps1 purges AppContainer profiles on uninstallation.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
解决问题 / Fixes
背景与根因分析 / Root Cause
在 Windows 11(特别是 24H2 / 25H2,Build 26100 及 26200)中,
AppXSvc服务(运行在NT AUTHORITY\SYSTEM)启用了PROCESS_MITIGATION_REDIRECTION_TRUST_POLICY(Redirection Trust 缓解策略)。在以下两种场景下,
Add-AppxPackage会尝试清理旧的 AppContainer 配置文件并调用DeleteAppContainerProfile:Register-ShareTarget.ps1和register-dev.ps1在执行Add-AppxPackage前,无差别调用了Remove-AppxPackage移除WeChatBridge.Windows.ShareTarget。Remove-AppxPackage卸载包后残留了未清理的 AppContainer 用户数据目录%LOCALAPPDATA%\Packages\<PackageFamilyName>。随后的Add-AppxPackage检测到旧状态,触发底层DeleteAppContainerProfile。Add-AppxPackage检测到孤儿 AppContainer 并尝试删除。当
AppXSvc(SYSTEM 权限)尝试遍历和删除标准用户目录中的AC目录时,因其包含 Windows 自动创建的 NTFS Reparse Points / Junctions(例如缓存和临时目录的联接点),NTFS 驱动根据 Redirection Trust 规则拒绝高权限服务穿越低权限创建的联接点,返回ERROR_UNTRUSTED_MOUNT_POINT(0x1C0,即0x800701C0),导致DeleteAppContainerProfile抛出IOException,进而导致Add-AppxPackage失败(0x80073CF6),整个 MSI 安装以0x80070643失败回滚。修复方案 / Solution
就地更新不提前卸载:
WeChatBridge.Windows.ShareTarget调用Remove-AppxPackage;ChatBridge.Windows.ShareTarget(1.0.7 残留)执行移除;Add-AppxPackage加上-ForceApplicationShutdown -ForceUpdateFromAnyVersion,由系统原生进行就地平滑升级,不触发 AppContainer 孤儿删除。用户态前置检测并彻底清理孤儿 AppContainer:
Clear-AppContainerProfiles函数;WeChatBridge.Windows.ShareTarget未注册(全新安装、重装或上次安装失败残留),在Add-AppxPackage前,以当前用户身份主动清理孤儿 AppContainer:[System.IO.Directory]::Delete($path, $false)安全解绑解开Packages目录中的全部 Junction / Reparse Point,避免触发0x800701C0;userenv.dll的DeleteAppContainerProfileAPI 彻底清除注册表与 StateRepository 记录;Mappings与Storage注册表项。异常重试容错:
Add-AppxPackage增加 try-catch 兜底,若首次调用失败,自动触发一次完整的 AppContainer 深度清理后再重试一次。卸载时清理干净:
Unregister-ShareTarget.ps1中加入 AppContainer 清理逻辑,卸载时彻底移除 profile,避免未来重新安装时留有隐患。本地开发脚本同步:
windows/scripts/register-dev.ps1中同步上述更新与清理逻辑。验证 / Verification
WeChatBridge.Windows.Tests287 通过,WeChatBridge.Windows.AppTests8 通过)。pack-msix.ps1打包成功;Test-SharePackage.ps1数据格式与资产契约校验全部通过;register-dev.ps1首次注册成功;WeChatBridge.ShareTarget.exe --registration-check验证包身份与 AUMID 获取完全正常;register-dev.ps1多次重复更新安装无报错;Unregister-ShareTarget.ps1卸载及 profile 清理测试正常;