SHGetFolderPath函数问题 [英] SHGetFolderPath Function Question

查看:69
本文介绍了SHGetFolderPath函数问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的电脑中,我有几个驱动程序,分别是C,D,E,F ......,而且我的所有驱动程序中都有程序文件(x86)。

我想使用SHGetFolderPath函数如下:

Hi,
In my PC I have several drivers same C,D,E,F,... and in all I have "Program Files (x86)" in all my drivers too.
I want use SHGetFolderPathfunction as below:

TCHAR szPath[MAX_PATH];

if(SUCCEEDED(SHGetFolderPath(NULL, 
                             CSIDL_PROGRAM_FILESX86|CSIDL_FLAG_CREATE, 
                             NULL, 
                             0, 
                             szPath))) 
{
    PathAppend(szPath, TEXT("New Doc.txt"));
    HANDLE hFile = CreateFile(szPath, ...);
}





问题在这里:

如何使用这个搜索并查找所有驱动器和为我的所有驱动器运行此功能?



问候,



Question is here:
How use this that search and find all drives and run this function for all my drives?

Regards,

推荐答案

根据对于MSDN,您可以为一个操作系统启动模式提供一个有效的Program Files文件夹。





这里是程序文件的实际结构如何。

GUID {905e63b6-c1bf -494e-b29c-65b732d3d21a}

显示名称程序文件

文件夹类型固定

默认路径%ProgramFiles%(%SystemDrive%\Program文件)

CSIDL等效CSIDL_PROGRAM_FILES

旧版显示名称程序文件

旧版默认路径%ProgramFiles%(%SystemDrive%\Program Files)



和以下64位机器可用选项。



OS应用程序KNOWNFOLDERID默认路径CSIDL等效

32位32位FOLDERID_ProgramFiles%SystemDrive%\Program Files CSIDL_PROGRAM_FILES

32位32位FOLDERID_ProgramFilesX86%SystemDrive%\Program Files CSIDL_PROGRAM_FILESX86

32位32位FOLDERID_ProgramFilesX64(未定义)不适用le不适用



好​​像,你有不同的操作系统启动选项,这些操作系统在不同的驱动器中有ProgramFiles。因此,根据您用于引导路径的操作系统,CSIDL_PROGRAM_FILESX86将指向注册表中该文件夹的相应GUID。您可能希望遍历不同驱动器的文件夹,以获取系统中的所有程序文件文件夹。



您可能希望查看FindFirstFile API并仅迭代文件夹(使用自定义函数区分文件和文件夹,例如boost :: filesystem :: is_directory())并将名称与您要搜索的文件夹名称进行比较。





干杯

Kushagra
According to MSDN you can have one valid Program Files folder for one OS boot mode.


Here, is how the actual structure of Program Files look like.
GUID {905e63b6-c1bf-494e-b29c-65b732d3d21a}
Display Name Program Files
Folder Type FIXED
Default Path %ProgramFiles% (%SystemDrive%\Program Files)
CSIDL Equivalent CSIDL_PROGRAM_FILES
Legacy Display Name Program Files
Legacy Default Path %ProgramFiles% (%SystemDrive%\Program Files)

and for a 64 bit machine following are the options available.

OS Application KNOWNFOLDERID Default Path CSIDL Equivalent
32 bit 32 bit FOLDERID_ProgramFiles %SystemDrive%\Program Files CSIDL_PROGRAM_FILES
32 bit 32 bit FOLDERID_ProgramFilesX86 %SystemDrive%\Program Files CSIDL_PROGRAM_FILESX86
32 bit 32 bit FOLDERID_ProgramFilesX64 (undefined) Not applicable Not applicable

Seems, you are having different OS boot options and these OS have ProgramFiles in different Drives. So, depending upon which OS you have used to boot the path CSIDL_PROGRAM_FILESX86 will point to corresponding GUID of that folder in the registry. You might want to iterate through folders of different drives inorder to get all program files folders in your system.

You might want to have a look on FindFirstFile API and iterate only folders (using a customized function to differentiate between file and folder eg. boost::filesystem::is_directory())with it and compare the name to the Folder name you are searching for.


Cheers
Kushagra


I不知道为什么在许多驱动器上有多个程序文件目录(可能是因为在机器之间传输硬盘驱动器)但通常你的系统中只有一个这样的目录,而且该目录由<$ c $返回c>您已经找到的SHGetFolderPath()。在64位Windows系统上,您可以有两个目录:一个用于32位应用程序的Program Files(x86)和一个用于64位应用程序的Program Files目录。
I don't know why do you have more than one program files directory on many drives (maybe because of transferring hard drives between machines) but normally you should have only one such directory in your system and that directory is returned by the SHGetFolderPath() that you already found out. On 64 bit windows systems you can have two directories: A "Program Files (x86)" for 32 bit applications and a "Program Files" directory for the 64 bit ones.


为什么不使用GetLogicalDrive()获取所有驱动器号,并在每个驱动器号上附加Program Files(x86),然后就可以获取文件路径。
Why not use GetLogicalDrive() to get all drive letters, and append the "Program Files (x86)" on each of them, then you can get the file paths.


这篇关于SHGetFolderPath函数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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