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

关于Chocolatey中Install-ChocolateyPackage未明文档softwareName参数的问询

Understanding the Undocumented softwareName Parameter in Install-ChocolateyPackage

Great question! The softwareName parameter in Chocolatey's Install-ChocolateyPackage is one of those underdocumented workhorses that makes package management smoother once you grasp its purpose. Let's break down exactly what it does and how to use it correctly.

What is softwareName?

At its core, this parameter is Chocolatey's way of identifying existing installations of your target software in the Windows registry (specifically the Uninstall keys). It’s critical for reliable uninstall, upgrade, and duplicate-install prevention logic—even though the official docs don’t dive into its nuanced rules.

Core Use Cases & Rules

1. Wildcard Matching (For Versioned or Variable Display Names)

Many applications have a DisplayName in the registry that includes a version number (e.g., Visual Studio Code 1.86.0). In these cases, using a wildcard (*) in softwareName lets Chocolatey match any version of the software:

  • How it works: Chocolatey scans the system’s uninstall registry entries for any entry whose DisplayName contains the text between wildcards.
  • Rule of thumb: Use wildcards when the software’s display name changes with each version, or when you need to match multiple variants of the same app (e.g., 32-bit vs 64-bit if their display names are nearly identical).

2. Exact Name Matching (For Fixed Display Names)

If the target software has a static, version-agnostic DisplayName (like 7-Zip or Notepad++), you can pass the exact display name as softwareName:

  • How it works: Chocolatey looks for an exact match (case-insensitive) in the registry’s DisplayName field.
  • Rule of thumb: Only use exact names when you’re certain the display name never changes between versions—this ensures precise targeting of the correct uninstall entry.

Practical Examples

Example 1: Wildcard Usage for Versioned Apps

Install-ChocolateyPackage `
  -PackageName "vscode" `
  -SoftwareName "*Visual Studio Code*" `
  -Url "https://code.visualstudio.com/sha/download?build=stable&os=win32-x64-user" `
  -UninstallArguments "/silent /norestart"

Here, *Visual Studio Code* matches any version of VS Code, regardless of the version number appended to its registry display name.

Example 2: Exact Name Usage for Fixed Display Name Apps

Install-ChocolateyPackage `
  -PackageName "7zip" `
  -SoftwareName "7-Zip" `
  -Url "https://www.7-zip.org/a/7z2301-x64.msi" `
  -UninstallArguments "/qn /norestart"

7-Zip’s registry DisplayName is always 7-Zip, so passing the exact name ensures Chocolatey targets the correct uninstall entry every time.

Common Pitfalls to Avoid

  • Overly broad wildcards: Using something like *Code* might accidentally match unrelated apps (e.g., JetBrains Rider if it includes "Code" in its display name). Keep wildcards as specific as possible.
  • Incorrect display names: Always verify the exact DisplayName in the registry (check HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall or HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall for user-specific installs) before setting softwareName.
  • Ignoring its role beyond uninstall: softwareName doesn’t just handle uninstalls—it also helps Chocolatey detect existing installations to skip redundant installs or trigger upgrade logic instead of a fresh install.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 04:32:55