PowerShell/MSI静默卸载Microsoft Report Viewer 2012 Runtime失败,求解决方案
问题回顾
我尝试过两种常见的静默卸载方法,但均未生效:
MSI方法
$ReportViewer2012 = Get-WmiObject -Class Win32_Product -Filter "Name = 'Microsoft Report Viewer 2012 Runtime'" | Select-Object -Expand IdentifyingNumber if ($ReportViewer2012) { echo "Uninstalling: Microsoft Report Viewer 2012 Runtime" msiexec /passive /x $ReportViewer2012 | Out-Null }
PowerShell方法
(Get-WMIObject Win32_Product -Filter 'name="Microsoft Report Viewer 2012 Runtime"').Uninstall()
通过/L*V参数获取的详细日志显示核心错误:
MSI (s) (20:84) [14:42:57:903]: SOURCEMGMT: Source is invalid due to missing/inaccessible package.
MSI (s) (20:84) [14:42:57:903]: Note: 1: 1706 2: -2147483647 3: ReportViewer.msi
MSI (s) (20:84) [14:42:57:903]: SOURCEMGMT: Failed to resolve source
MSI (s) (20:84) [14:42:57:903]: MainEngineThread is returning 1612
问题原因分析
日志里的1612错误是关键,这表示Windows Installer无法找到程序的原始安装源文件。MSI程序在卸载时,偶尔需要调用原始安装包来完成组件清理、回滚校验等操作,如果原始安装介质(比如U盘、网络共享)已移除,或者系统缓存的安装包被清理,就会触发这个“找不到源”的问题。
可行解决办法
1. 指定原始安装包路径卸载
找到Microsoft Report Viewer 2012 Runtime的原始MSI安装包,在卸载命令中通过SOURCE参数指定路径:
$ReportViewer2012 = Get-WmiObject -Class Win32_Product -Filter "Name = 'Microsoft Report Viewer 2012 Runtime'" | Select-Object -Expand IdentifyingNumber if ($ReportViewer2012) { echo "Uninstalling: Microsoft Report Viewer 2012 Runtime" msiexec /passive /x $ReportViewer2012 SOURCE="C:\Your\Path\To\ReportViewer.msi" | Out-Null }
或者直接用CMD命令替换{ProductCode}为你获取到的IdentifyingNumber:
msiexec /x {ProductCode} SOURCE="C:\Your\Path\To\ReportViewer.msi" /passive
2. 重新安装后再卸载
先下载并完整安装Microsoft Report Viewer 2012 Runtime(确保安装过程无报错),这会修复Windows Installer的源文件关联信息,之后再用你之前的卸载命令尝试操作,大概率能正常完成卸载。
3. 使用微软官方卸载修复工具
微软提供的Program Install and Uninstall Troubleshooter可以自动检测并修复Windows Installer相关的卸载问题,包括源文件缺失的情况。运行工具后选择“卸载”选项,找到目标程序并按照引导操作即可。
4. 手动清理(谨慎操作)
如果以上方法都无效,可以尝试手动清理(注意:修改注册表有风险,建议先备份):
- 打开注册表编辑器(
regedit.exe),定位到HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall和HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall,找到对应ProductCode的项并删除。 - 删除程序的安装目录(默认路径类似
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Report Viewer)。 - 清理Windows Installer缓存:前往
C:\Windows\Installer,找到与Report Viewer对应的缓存文件(可通过ProductCode匹配)并删除。
内容的提问来源于stack exchange,提问作者Dave R

