我的程序应如何决定安装在“Program Files (x86)”下?

发布于 2024-10-05 15:30:32 字数 356 浏览 3 评论 0原文

出于好奇,如果我正在创建程序安装程序,我应该如何决定安装到哪个“Program Files”目录?在 32 位系统上,环境变量“%programfiles%”就足够了。但是,在 64 位系统上,32 位程序不应安装到该文件夹​​,而应安装到“%programfiles(x86)%”,据我所知,它指向“C:\Program Files (x86)”。我的问题是:安装程序应如何决定使用哪个环境变量?对于 32 位应用程序,“%programfiles%”的值是否会改变,或者我应该在使用“%programfiles%”之前首先检查“%programfiles(x86)%”是否存在,或者我应该做一些完全不同的事情?

谢谢!这只是出于我自己的好奇心,因为我试图习惯 64 位操作系统。

Just out of curiosity, if I am creating a program installer, how should I decide in which "Program Files" directory to install to? On 32-bit systems, the environmental variable "%programfiles%" is good enough. However, on 64-bit systems, 32-bit programs should not install to that folder and instead to "%programfiles(x86)%", which as I understand points to "C:\Program Files (x86)". My question is: How should the installer decide which environment variable to use? Will the value of "%programfiles%" change for a 32-bit application, or should I always check first whether "%programfiles(x86)%" exists before using "%programfiles%", or should I do something entirely different?

Thanks! This is just out of my own curiosity, as I try to get used to 64-bit operating systems.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深府石板幽径 2024-10-12 15:30:32

当 32 位程序(在您的情况下是安装程序)要求系统解析 ProgramFilePath 常量(在 MSDN 中检查确切名称)时,系统不会返回 C:\Program files,而是返回 C: \程序文件(x86)。所以决定的是系统,而不是应用程序。

When the 32-bit program (installer in your case) asks the system to resolve the ProgramFilePath constant (check the exact name in MSDN), the system does not return C:\Program files, but C:\Program files(x86). So it's the system that decides, not the application.

鼻尖触碰 2024-10-12 15:30:32

我很确定我在某处读到 Windows 会自动为您完成此操作。换句话说,如果您的安装程序是 32 位,即使您尝试安装到 Program Files 中,它也会被路由到 x86 目录变体。

我确定我在《旧新事物》上读过这篇文章,但是 这里有一个链接,它支持争用,直到我找到该链接。


啊,是的,在这里,来自非常有用的 Raymond Chen

评论者 Koro 正在以 32 位程序的形式编写一个安装程序,该程序检测到它正在 64 位系统上运行,并希望将文件(并可能设置注册表项并执行其他安装程序操作)复制到 64 位系统中位目录,但仿真层将操作重定向到 32 位位置。问题是“从 32 位应用程序中查找 x64 Program Files 目录的方法是什么?”

答案是“与系统合作比反对它更好。”如果您是 32 位程序,那么每次尝试与外界交互时,您都会与模拟器作斗争。相反,只需将安装程序重新编译为 64 位程序即可。让 32 位安装程序检测到它正在 64 位系统上运行,然后启动 64 位安装程序。 64位安装程序不会在32位模拟层中运行,因此当它尝试复制文件或更新注册表项时,它将看到真正的64位文件系统和真正的64位注册表。

I'm pretty certain that I read somewhere that Windows did this for you automagically. In other words, if your installer was 32-bits, it would be routed to the x86 directory variant even though you were trying to install into Program Files.

I'm sure I read this on The Old New Thing but here's a link that supports the contention until I can find that one.


Ah, yes, here it is, from the ever useful Raymond Chen.

Commenter Koro is writing an installer in the form of a 32-bit program that detects that it's running on a 64-bit system and wants to copy files (and presumably set registry entries and do other installery things) into the 64-bit directories, but the emulation layer redirects the operations into the 32-bit locations. The question is "What is the way of finding the x64 Program Files directory from a 32-bit application?"

The answer is "It is better to work with the system than against it." If you're a 32-bit program, then you're going to be fighting against the emulator each time you try to interact with the outside world. Instead, just recompile your installer as a 64-bit program. Have the 32-bit installer detect that it's running on a 64-bit system and launch the 64-bit installer instead. The 64-bit installer will not run in the 32-bit emulation layer, so when it tries to copy a file or update a registry key, it will see the real 64-bit file system and the real 64-bit registry.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文