Windows 95 防御安装程序覆盖较旧文件的机制
Windows 95 defenses against installers that overwrite a file with an older one

原始链接: https://devblogs.microsoft.com/oldnewthing/20260324-00/?p=112159

在16位Windows时代,程序安装包经常包含并重新安装系统组件。理想情况下,安装包应该只*更新*已有的组件到新版本,并尊重Windows的向下兼容性。然而,许多安装包会随意覆盖文件,有时甚至用旧的Windows 3.1版本替换掉较新的Windows 95版本,导致系统不稳定。 Windows 95巧妙地通过创建`C:\Windows\SYSBCKUP`目录来解决这个问题。每次安装后,它会检查是否有系统文件被覆盖。如果替换版本*比*备份版本旧,Windows会恢复原始文件。 早期尝试*阻止*覆盖失败了——安装包要么崩溃,要么提示用户困惑,或者找到方法强制覆盖。最终,允许安装包运行,然后在安装后“清理”被证明是最可靠的解决方案。一些组件甚至强制执行自己的安装程序,以防止由于安装包不可靠而直接替换文件。

## Windows 95 安装程序混乱:总结 微软devblogs.microsoft.com上的一篇最近帖子详细介绍了Windows 95团队在处理行为不当的安装程序时面临的挑战。许多安装程序会用旧版本覆盖系统文件,可能导致操作系统或其他应用程序崩溃。微软的解决方案出人意料地务实:Windows 95 会在隐藏目录 (`C:\Windows\SYSBCKUP`) 中秘密备份经常被覆盖的文件,并在安装后恢复它们。 讨论强调了一个核心问题:开发者常常优先保证*他们*的软件能够运行,即使这意味着无视最佳实践或直接破坏系统稳定性。 有限的文档、缺乏标准化的安装程序以及没有自动更新功能加剧了这一问题。 评论员指出微软历史上优先考虑向后兼容性——破坏现有软件会面临失去客户的风险。一些人建议采取替代方法,例如点名并谴责有问题软件,但最终承认执行标准是困难的。对话还涉及现代的相似之处,例如 Zig 语言对未记录的 Windows API 的使用,以及 Windows 的 `WinSxS` 目录和 Linux 中的包管理器的演变。最终,这个故事展示了一个软件开发中务实主义常常胜过理想设计的有趣时期。
相关文章

原文

Back in the days of 16-bit Windows, many system components were redistributable, meaning that programs that used those components could include a copy of those system components and install them onto the system as part of the program’s installer. The guidance for installing the system components was that if the installer finds a copy of the system component already on the system, then they should compare the version number of the existing file with the version number of the file being installed and then overwrite the file only if the file being installed has a higher version number. if the existing file has a higher version number, then it should be left alone.

This rule relies on the fact that Windows maintains backward compatibility, so the newer version still works even if used by an older program.

This doesn’t mean that installers actually followed this guidance.

It was common for program installers to overwrite any file that was in their way, regardless of the existing file’s version number. When these installers ran on Windows 95, the replaced the Windows 95 versions of the components with the Windows 3.1 versions. You can imagine how much of a disaster this caused to the rest of the system.

Windows 95 worked around this by keeping a backup copy of commonly-overwritten files in a hidden C:\Windows\SYSBCKUP directory. Whenever an installer finished, Windows went and checked whether any of these commonly-overwritten files had indeed been overwritten. If so, and the replacement has a higher version number than the one in the SYSBCKUP directory, then the replacement was copied into the SYSBCKUP directory for safekeeping. Conversely, if the replacement has a lower version number than the one in the SYSBCKUP directory, then the copy from SYSBCKUP was copied on top of the rogue replacement.

Basically, Windows 95 waited for each installer to finish, and then went back and checked its work, fixing any mistakes that the installer made.

An earlier design simply blocked the installer’s attempt to overwrite the file, but this ended up creating more problems. Some installers declared the installation to be a failure and gave up. Otherwise displayed an error message to the user and asked the user what to do next. (Like the user knows what to do next.) You even had installers that took even more extreme measures and said, “Okay, fine, I can’t overwrite the file, so I’m going to reboot the system and then overwrite the file from a batch file, see if you can stop me.”

Redirecting the write to a dummy file didn’t work because some installers had a validation step where they checked that the files on disk have the correct checksum, so they would notice that their attempt to overwrite the file was unsuccessful and error out.

The way that worked best was to let the installer overwrite anything it wanted and then go back and try to clean up the mess.

Bonus chatter: Some components addressed this problem by providing their own installer for the component, and telling installers, “You are not allowed to install these component file directly. Instead, you must run our custom installer. Yes, this disrupts your installer’s UI, but you installer authors have shown that you can’t be trusted to install files on your own. It’s your own fault.”

联系我们 contact @ memedata.com