为什么 Chocolatey 不将软件包安装到“C:\Program Files\”中?

Why doesn't Chocolatey install packages into `C:\Program Files\`?

根据Windows安装规则,程序应该安装到 C:\Program Files(64 位程序/x86-64)或C:\Program Files (x86)(32 位程序/x86)。该程序被复制到包含供应商名称和程序名称的子子文件夹中。

但为什么 Chocolatey 不将软件包安装到 C:\Program Files\<Vendor>\<Program>\ 中?

10. Apps must install to the correct folders by default
Users should have a consistent and secure experience with the default installation location of files, while maintaining the option to install an app in the location of their choice. It is also necessary to store app data in the correct location to allow several people to use the same computer without corrupting or overwriting each other's data and settings. Windows provides specific locations in the file system to store programs and software components, shared app data, and app data specific to a user

10.1 Your app must be installed in the Program Files folder by default
For native 32-bit and 64-bit apps in %ProgramFiles%, and %ProgramFiles(x86)% for 32-bit apps running on x64. User data or app data must never be stored in this location because of the security permissions configured for this folder.

来源:Certification requirements for Windows desktop apps
版本:10(2015 年 7 月 29 日)

这取决于您的 Chocolatey 版本、它的设置和 软件包本身

To start, see Tools vs Applications and Chocolatey's distinction ( https://github.com/chocolatey/chocolatey/wiki/ChocolateyFAQs at the bottom).

If the package does not use a native installer (a tool), it depends on if the package author has used the bin_root concept that is up and coming in a future version.

For example, SysInternals will go to c:/sysinternals right now unless you have a defined $env:chocolatey_bin_root variable. The concept in the code will change as well as right now this requires it to be a subfolder of the system drive and I don't see us developing the final feature with that limitation.

If the package doesn't have that concept yet, one can always ask the package author to incorporate it.

If the package uses a native installer (an application), one can use installArgs to pass arguments to the native installer (https://github.com/chocolatey/chocolatey/wiki/CommandsInstall) and tell it the directory to install the application to. This does require you to know what you need to pass to the native installer. If you want your applications in a custom directory, there is an assumption that you are already an advanced user so it is expected that you would know what to pass the installer if you were doing a silent install.

略微转述自:https://groups.google.com/forum/#!msg/chocolatey/uucAz8GxebA/HEPAKp69d90J

此外,

NOTICE: As of 0.9.8.24, Chocolatey's default install location is C:\ProgramData\Chocolatey

This reduces the attack surface on a local installation of chocolatey and limits who can make changes to the directory.

来源:https://github.com/chocolatey/chocolatey/wiki/DefaultChocolateyInstallReasoning

根据个人经验,我可以证明这个概念是一道很好的防线(如果配置、使用和理解得当)。

PS:
正如您已经添加到答案中的那样,从技术上讲,要求是 %ProgramFiles%%ProgramFiles(x86)% 环境变量(如适用)。
例如,%ProgramFiles(x86)% 也可以指向 P:\Software\Programs\x86\(而不是 C:\Program Files (x86)\)。
显然有很多遗留软件(现在(重新)打包)从未在路径名中使用 <vendor> 部分。

希望对您有所帮助!