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?

查看:109
本文介绍了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

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_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion

您对字符串值感兴趣:


ProgramFilesDir

ProgramFilesDir

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

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