记录一次非标准路径安装 VS2022 和 Windows SDK 的踩坑全过程以及 WPT Ghost 残留问题的终极解决方案。背景目标很简单安装Visual Studio 2022 Community到E:\TOOLS\vs2022Comunity安装Windows SDK 10.0.22621排除不需要的 SDK 版本26100和 Windows Performance ToolkitWPT看起来是标准操作但实际过程充满了各种诡异的错误。第一关WPT Ghost 弹窗地狱现象在安装过程中每次涉及 WPTWindows Performance Toolkit的操作都会弹出一个 Windows Installer 错误框The path C:\ProgramData\Package Cache\{EC12C121-3208-5E92-FCB0-0591769632F9}\ v10.1.18362.1\Installers\WPTx64-x86_en-us.msi cannot be found.点了无数次取消按钮弹窗又冒出来简直是无限弹窗地狱。原因分析系统之前安装过旧版 WPTv10.1.18362.1但 MSI 安装源文件被清理了C:\ProgramData\Package Cache中的文件已被删除。Windows 留下了两个ghost 产品残留在 MSI 数据库中Ghost ID产品{EC12C121-3208-5E92-FCB0-0591769632F9}WPTx64{A8E21603-6CBA-D168-ADF7-108A1DA16DB5}WPT Redistributables每当安装程序试图修复、升级或卸载这些产品时MSI 就会尝试查找安装源文件找不到就弹窗。尝试过的方案均失败1. 清理注册表 Uninstall 项删除了HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall中对应的条目。结果无效。这些只是显示层面的清理MSI 内部数据库仍然记录着这些产品。2. 在 VS Installer 中排除 WPT 组件setup.exe modify --installPath E:\TOOLS\vs2022Comunity --remove Microsoft.VisualStudio.Component.Windows11Sdk.WindowsPerformanceToolkit结果WPT 标记为 NotSelected但其他操作仍然会触发 ghost 的修复尝试。3. 创建假 MSI 文件在C:\ProgramData\Package Cache\{EC12C121-...}\下放置了一个占位 MSI 文件试图骗过 MSI。结果MSI 验证文件签名/哈希失败弹窗继续。4. winget 安装 SDKwinget install Microsoft.WindowsSDK.10.0.22621结果错误 1618 — 另一个 MSI 安装正在进行中WPT ghost 的残留进程占用了 MSI 互斥锁。5. 独立 SDK 安装器下载并运行winsdksetup.exe /quiet。结果静默安装后无报错但 SDK 并未实际安装同样被 WPT ghost 阻塞。终极方案深度清理 MSI 数据库经过研究WPT ghost 的根源不在注册表 Uninstall 项而在MSI 内部数据库的三个位置HKLM\SOFTWARE\Classes\Installer\Products\ProductCodeHKLM\SOFTWARE\Classes\Installer\Features\ProductCodeHKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\ComponentGUIDProductCode 计算规则MSI 注册表中的 ProductCode 是原始 GUID 的反转字节序形式。原始: {EC12C121-3208-5E92-FCB0-0591769632F9} 反转: 121C21CE 8023 29E5 CF0B 50196769239F即将前 3 部分的每个 4 位十六进制字节序反转后 2 部分保持原样。深度清理脚本# deep_clean_wpt.ps1 ​ $wptGuid {EC12C121-3208-5E92-FCB0-0591769632F9} ​ # 计算反转的 ProductCode function Reverse-GuidBytes { param([string]$guid) $clean $guid -replace [{}], $parts $clean -split - $p1 -join ($parts[0][6],$parts[0][7],$parts[0][4],$parts[0][5], $parts[0][2],$parts[0][3],$parts[0][0],$parts[0][1]) $p2 -join ($parts[1][2],$parts[1][3],$parts[1][0],$parts[1][1]) $p3 -join ($parts[2][2],$parts[2][3],$parts[2][0],$parts[2][1]) return $p1$p2$p3$($parts[3])$($parts[4]) } ​ $reversedCode Reverse-GuidBytes -guid $wptGuid ​ # 1. 删除 Products 键 $productPath HKLM:\SOFTWARE\Classes\Installer\Products\$reversedCode if (Test-Path $productPath) { Remove-Item -Path $productPath -Recurse -Force Write-Host [OK] Removed Products key } ​ # 2. 删除 Features 键 $featurePath HKLM:\SOFTWARE\Classes\Installer\Features\$reversedCode if (Test-Path $featurePath) { Remove-Item -Path $featurePath -Recurse -Force Write-Host [OK] Removed Features key } ​ # 3. 删除 Components 关联 $componentsPath HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components Get-ChildItem $componentsPath | ForEach-Object { $value (Get-ItemProperty -Path $_.PSPath -Name $reversedCode -ErrorAction SilentlyContinue).$reversedCode if ($value) { Remove-ItemProperty -Path $_.PSPath -Name $reversedCode -Force Write-Host [OK] Removed Component: $($_.PSChildName) } }执行结果[OK] Removed Products key [OK] Removed Features key [OK] Removed Component: B79AA12C5E96CCC4D9B263E0B3BED119 ​ SUCCESS: WPTx64 completely removed3 个残留注册表项全部清除。另一个 ghost{A8E21603-...}在之前的操作中已被清除。第二关SDK 终于安装WPT ghost 清除后通过 VS Installer 的 modify 命令安装 SDK 22621 C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe modify --installPath E:\TOOLS\vs2022Comunity --quiet --norestart --add Microsoft.VisualStudio.Component.Windows11SDK.22621这一次安装成功完成没有弹窗安装位置说明SDK 被安装到了D:\Windows Kits\10\而非默认的C:\Program Files (x86)\Windows Kits\10\因为注册表中KitsRoot10已经指向 D 盘。目录结构D:\Windows Kits\10\ ├── Include\10.0.22621.0\ │ ├── shared\ (共享头文件) │ ├── um\ (User Mode) │ ├── winrt\ (WinRT) │ └── cppwinrt\ (C/WinRT) └── Lib\10.0.22621.0\ └── um\x64\ (64位库文件)第三关VS 无法自动找到 SDK现象使用vcvars64.bat激活 MSVC 环境后cl.exe编译时找不到windows.hmain.cpp(1): fatal error C1083: 无法打开包括文件: windows.h: No such file or directory原因vcvars64.bat默认在$(VC_VC_ProgramFilesx86)\Windows Kits\10\Include下查找 SDK但实际 SDK 在D:\Windows Kits\10\。解决方案方案一手动指定路径cl /EHsc /std:c17 ^ /ID:\Windows Kits\10\Include\10.0.22621.0\um ^ /ID:\Windows Kits\10\Include\10.0.22621.0\shared ^ /ID:\Windows Kits\10\Include\10.0.22621.0\winrt ^ /ID:\Windows Kits\10\Include\10.0.22621.0\cppwinrt ^ main.cpp ^ /link /LIBPATH:D:\Windows Kits\10\Lib\10.0.22621.0\um\x64方案二CMake 配置cmake_minimum_required(VERSION 3.20) project(HelloWorld) # 手动指定 SDK 版本和路径 set(CMAKE_SYSTEM_VERSION 10.0.22621.0) add_executable(helloworld main.cpp)方案三修改 Windows SDK 注册表如果希望vcvars自动识别可以在HKLM\SOFTWARE\Microsoft\Windows Kits\Installed Roots中确认KitsRoot10指向正确路径并确保版本子键10.0.22621.0存在。验证结果编译并运行 Hello World 程序Hello World from Visual Studio 2022! Windows SDK Version: 167772172 Build timestamp: Jul 10 2026 15:02:48组件版本状态MSVC 编译器19.44.35228✅Windows SDK10.0.22621.0✅头文件shared/um/winrt/cppwinrt✅库文件um/x64✅总结关键经验1. MSI Ghost 问题本质MSI 产品残留存储在多个注册表位置仅删除 Uninstall 项是不够的。必须清理HKLM\SOFTWARE\Classes\Installer\Products\ReversedGUIDHKLM\SOFTWARE\Classes\Installer\Features\ReversedGUIDHKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\GUID⚠️注意MSI 注册表中的 ProductCode 使用字节反转格式不是原始 GUID 格式2. 排查思路弹窗错误 → 确定 MSI 产品 GUID → 计算反转 ProductCode → 搜索 Products/Features/Components 三个位置 → 逐个删除 → 重启 → 重新安装3. 工具链建议MSI 清理使用msiexec /x {GUID}正常卸载不要手动删文件SDK 安装优先通过 VS Installer 安装而非独立安装器非标准路径注意注册表KitsRoot10指向的位置编译验证先写一个简单程序验证工具链完整性4. 时间线阶段耗时状态初始安装 VS2022正常✅WPT ghost 弹窗~2h 各种尝试❌深度清理 MSI 数据库5min✅SDK 22621 安装正常✅编译验证2min✅总计折腾时间约 2-3 小时其中 90% 的时间花在 WPT ghost 问题的排查和无效尝试上。参考MSI ProductCode 格式说明Windows SDK 安装器命令行选项VS Installer 命令行参数写于 2026-07-10希望这篇记录能帮助遇到同样问题的人少走弯路。