32 位应用程序如何在 Windows Vista 64 位上找到 64 位 Program Files 目录的位置? [英] How can 32-bit application find the location of 64-bit Program Files directory on Windows Vista 64-bit?

查看:32
本文介绍了32 位应用程序如何在 Windows Vista 64 位上找到 64 位 Program Files 目录的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力解决如何从 32 位应用程序确定 64 位 Windows Vista 上 64 位 Program Files 目录的位置的问题.

I'm struggling with a problem of how to determine the location of the 64-bit Program Files directory on 64-bit Windows Vista from a 32-bit application.

调用 SHGetKnownFolderPath(FOLDERID_ProgramFilesX64) 不会返回任何内容.MSDN 文章KNOWNFOLDERID 还声明不支持使用 FOLDERID_ProgramFilesX64 的这个特定调用32 位应用程序.

Calls to SHGetKnownFolderPath(FOLDERID_ProgramFilesX64) do not return anything. The MSDN article KNOWNFOLDERID also states that this particular call with FOLDERID_ProgramFilesX64 is not supported for a 32-bit application.

我想尽可能避免将路径硬编码到C:Program Files".执行类似 GetWindowsDirectory() 的操作,从返回值中提取驱动器并添加Program Files"对它也没有吸引力.

I would like to avoid as much as possible hardcoding the path to "C:Program Files". Doing something like GetWindowsDirectory(), extracting the drive from the return value and adding "Program Files" to it is not appealing either.

32 位应用程序如何从 64 位 Windows Vista 正确获取文件夹的位置?

How can a 32-bit application properly get the location of the folder from 64-bit Windows Vista?

我们的应用程序有一个服务组件,它应该根据来自用户会话特定组件的请求启动其他进程.启动的应用程序可以是 32 位或 64 位.我们通过 CreateProcessAsUser() 通过传入来自启动用户会话过程的令牌来做到这一点.为了调用 CreateProcessAsUser,我们通过 CreateEnvironmentBlock() API 创建一个环境块.问题在于 CreateEnvironmentBlock() 使用用户会话应用程序的令牌创建了一个 ProgramW6432=C:Program Files (x86)"的块,这对于 64-位应用程序.我们需要用适当的值覆盖它.

Our application has a service component which is supposed to launch other processes based on requests from user-session-specific component. The applications launched can be 32-bit or 64-bit. We do this is via CreateProcessAsUser() by passing in a token from initiating user-session process. For call to CreateProcessAsUser, we create an environment block via the CreateEnvironmentBlock() API. The problem is that CreateEnvironmentBlock(), using the token of the user-session application, creates a block with ProgramW6432="C:Program Files (x86)", which is a problem for 64-bit applications. We need to override it with the proper value.

推荐答案

正如您所提到的,在 32 位应用程序中使用 SHGetKnownFolderPath 在 64 位操作系统上不起作用.这是因为 Wow64 仿真有效.

As you mentioned, using SHGetKnownFolderPath from a 32-bit application will not work on a 64-bit operating system. This is because Wow64 emulation is in effect.

然而,您可以使用 RegOpenKeyEx 传入标志 KEY_WOW64_64KEY 然后从注册表中读取程序文件目录.

You can however use RegOpenKeyEx passing in the flag KEY_WOW64_64KEY and then read the program files directory from registry.

注册表中的位置:

HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersion

HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersion

您对字符串值感兴趣:

程序文件目录

这篇关于32 位应用程序如何在 Windows Vista 64 位上找到 64 位 Program Files 目录的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆