You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取类似控制面板的完整应用列表?PowerShell脚本问题求助

解决PowerShell无法列出全部已安装应用及卸载问题

你用Get-WmiObject Win32_Product的核心问题在于:这个WMI类只识别通过Windows Installer(MSI格式)安装的程序,像Google Chrome这类用EXE安装的应用、UWP应用,根本不会出现在它的结果里。而且Win32_Product还有个隐形坑——每次调用它都会触发MSI的自我修复检查,可能弹出不必要的程序修复窗口,完全不推荐使用。

替换应用列表获取方式

要获取系统中所有已安装应用,得读取系统注册表,所有程序的安装信息都存在以下两个路径:

  • 64位程序:HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall
  • 32位程序(64位系统):HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall

优化后的完整脚本

直接让你可视化选择应用,不用手动输入名称,还能正确卸载各类程序:

$ComputerName = Read-Host -Prompt 'Input the computer name'

# 获取所有已安装应用(覆盖32/64位、MSI/EXE安装的程序)
$allApps = Get-ChildItem -Path @(
    "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall",
    "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
) | Get-ItemProperty | Where-Object { $_.DisplayName -and $_.UninstallString } | 
    Select-Object DisplayName, UninstallString | Sort-Object DisplayName

# 用GridView让用户选择要卸载的应用
$selectedApp = $allApps | Select-Object DisplayName | Out-GridView -Title "Select app to uninstall" -OutputMode Single

if ($selectedApp) {
    # 匹配选中应用的完整卸载信息
    $appToUninstall = $allApps | Where-Object { $_.DisplayName -eq $selectedApp.DisplayName }
    $uninstallString = $appToUninstall.UninstallString

    # 自动适配MSI和EXE类程序的卸载逻辑
    if ($uninstallString -match 'msiexec.exe') {
        # MSI程序添加安静卸载参数,避免弹窗
        $msiArgs = $uninstallString -replace 'msiexec.exe', 'msiexec.exe /qn'
        Start-Process -FilePath 'msiexec.exe' -ArgumentList $msiArgs -Wait
    } else {
        # 拆分EXE路径和参数,处理带引号的路径
        $uninstallParts = $uninstallString -split ' ', 2
        $exePath = $uninstallParts[0].Trim('"')
        $exeArgs = if ($uninstallParts.Count -gt 1) { $uninstallParts[1] } else { '' }
        Start-Process -FilePath $exePath -ArgumentList $exeArgs -Wait
    }

    Write-Host "卸载完成:$($selectedApp.DisplayName)"
} else {
    Write-Host "未选择任何应用"
}

Start-Sleep -Seconds 10

脚本说明

  • 读取双注册表路径,确保不会漏掉32位或64位程序
  • 过滤掉无显示名称、无卸载命令的无效条目
  • 用Out-GridView的单选模式,彻底避免手动输入名称的拼写错误
  • 自动区分MSI和EXE卸载逻辑,添加安静参数减少弹窗干扰
  • 用Start-Process -Wait等待卸载完成后再提示结果

内容的提问来源于stack exchange,提问作者Minus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 17:05:44