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

如何获取Chocolatey软件包默认安装路径?脚本返回空值怎么办

解决Chocolatey Get-AppInstallLocation返回空路径的问题

排查与修复方案

1. 调整应用名称匹配规则

Get-AppInstallLocation通过匹配Windows注册表的应用条目返回路径,你使用的通配符'Mozilla Firefox*ESR'可能未命中正确的注册表项。尝试更精准的匹配:

$location = Get-AppInstallLocation 'Mozilla Firefox ESR'

或者直接使用注册表中显示的完整名称(比如64位版本):

$location = Get-AppInstallLocation 'Mozilla Firefox (64-bit ESR)'

2. 手动验证注册表条目

直接查询注册表,确认Firefox ESR的安装路径是否存在:

Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' | 
Where-Object { $_.DisplayName -like '*Firefox*ESR*' } | 
Select-Object DisplayName, InstallLocation

如果这条命令能返回有效路径,说明Get-AppInstallLocation的匹配逻辑存在偏差,你可以直接用上述命令提取路径。

3. 更新chocolatey-core.extension扩展

旧版本的扩展可能存在注册表解析缺陷,执行以下命令更新:

choco upgrade chocolatey-core.extension -y

4. 检查Firefox ESR的安装渠道

如果Firefox ESR不是通过Chocolatey安装的,Get-AppInstallLocation可能无法识别。此时可以直接检查系统默认安装路径:

# 检查64位默认路径
$64BitPath = "C:\Program Files\Mozilla Firefox ESR"
if (Test-Path $64BitPath) { Write-Output $64BitPath }

# 检查32位默认路径
$32BitPath = "C:\Program Files (x86)\Mozilla Firefox ESR"
if (Test-Path $32BitPath) { Write-Output $32BitPath }

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 02:22:33