如何从 32 位 WOW 进程获取 Program Files 文件夹路径(不是 Program Files (x86))? [英] How to get Program Files folder path (not Program Files (x86)) from 32bit WOW process?

查看:50
本文介绍了如何从 32 位 WOW 进程获取 Program Files 文件夹路径(不是 Program Files (x86))?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从 32 位 WOW 进程获取本机(而不是 WOW)程序文件目录的路径.

I need to get the path to the native (rather than the WOW) program files directory from a 32bit WOW process.

当我将 CSIDL_PROGRAM_FILES(或 CSIDL_PROGRAM_FILESX86)传递到 SHGetSpecialFolderPath 时,它返回 WOW(程序文件 (x86))文件夹路径.

When I pass CSIDL_PROGRAM_FILES (or CSIDL_PROGRAM_FILESX86) into SHGetSpecialFolderPath it returns the WOW (Program Files (x86)) folder path.

如果可能,我宁愿避免使用环境变量.

I'd prefer to avoid using an environment variable if possible.

我想比较我从注册表中读取的一些值,如果这些值指向我的应用程序的 WOW 或本机版本的路径,那么我的代码会执行某些操作,否则它会执行其他操作.要弄清楚我的应用程序的本机和 WOW 版本应该在哪里,我需要获取Program Files (x86)"和Program Files"的路径.

I want to compare some values I read from the registry, if the values point to the path of either the WOW or native version of my app then my code does something, if not it does something else. To figure out where the native and WOW versions of my app are expected to be I need to get the paths to "Program Files (x86)" and "Program Files".

推荐答案

我感谢所有帮助,尤其是该线程中的警告.但是,我确实需要这条路径,这就是我最终得到它的方式:

I appreciate all the help and, especially, the warnings in this thread. However, I really do need this path and this is how I got it in the end:

(为了清楚起见,删除了错误检查,使用风险自负等)

(error checking removed for clarity, use at your own risk, etc)

WCHAR szNativeProgramFilesFolder[MAX_PATH];
ExpandEnvironmentStrings(L"%ProgramW6432%", 
                       szNativeProgramFilesFolder, 
                       ARRAYSIZE(szNativeProgramFilesFolder);

这篇关于如何从 32 位 WOW 进程获取 Program Files 文件夹路径(不是 Program Files (x86))?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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